From 4b638634fac777fbdc9bba83ff4ffde3a7c72c42 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 31 Dec 2020 16:22:41 -0500 Subject: [PATCH] Remove old syncthing instance --- prod/syncthing-packer/terraform/main.tf | 57 ------------------- prod/syncthing-packer/terraform/outputs.tf | 11 ---- prod/syncthing-packer/terraform/terraform.tf | 18 ------ prod/syncthing-packer/terraform/variables.tf | 11 ---- .../.gitignore | 0 prod/syncthing/ansible/.envrc | 1 - prod/syncthing/ansible/hosts.ini | 1 - .../packer/Makefile | 0 .../packer/do.ini.template | 0 .../packer/packer-manifest.json | 0 .../packer/syncthing-cert.pem.template | 0 .../packer/syncthing-config.xml.template | 0 .../packer/syncthing-key.pem.template | 0 .../packer/syncthing.conf | 0 .../packer/syncthing.json | 0 .../packer/syncthing@.service | 0 .../terraform/.terraform.lock.hcl | 0 prod/syncthing/terraform/main.tf | 49 ++++++++++++++-- prod/syncthing/terraform/outputs.tf | 10 ++-- prod/syncthing/terraform/terraform.tf | 2 +- 20 files changed, 49 insertions(+), 111 deletions(-) delete mode 100644 prod/syncthing-packer/terraform/main.tf delete mode 100644 prod/syncthing-packer/terraform/outputs.tf delete mode 100644 prod/syncthing-packer/terraform/terraform.tf delete mode 100644 prod/syncthing-packer/terraform/variables.tf rename prod/{syncthing-packer => syncthing}/.gitignore (100%) delete mode 100644 prod/syncthing/ansible/.envrc delete mode 100644 prod/syncthing/ansible/hosts.ini rename prod/{syncthing-packer => syncthing}/packer/Makefile (100%) rename prod/{syncthing-packer => syncthing}/packer/do.ini.template (100%) rename prod/{syncthing-packer => syncthing}/packer/packer-manifest.json (100%) rename prod/{syncthing-packer => syncthing}/packer/syncthing-cert.pem.template (100%) rename prod/{syncthing-packer => syncthing}/packer/syncthing-config.xml.template (100%) rename prod/{syncthing-packer => syncthing}/packer/syncthing-key.pem.template (100%) rename prod/{syncthing-packer => syncthing}/packer/syncthing.conf (100%) rename prod/{syncthing-packer => syncthing}/packer/syncthing.json (100%) rename prod/{syncthing-packer => syncthing}/packer/syncthing@.service (100%) rename prod/{syncthing-packer => syncthing}/terraform/.terraform.lock.hcl (100%) diff --git a/prod/syncthing-packer/terraform/main.tf b/prod/syncthing-packer/terraform/main.tf deleted file mode 100644 index 82e7676..0000000 --- a/prod/syncthing-packer/terraform/main.tf +++ /dev/null @@ -1,57 +0,0 @@ -provider "digitalocean" { - token = var.do_token - spaces_access_id = var.spaces_access_id - spaces_secret_key = var.spaces_secret_key -} - -data "terraform_remote_state" "do_ssh_keys" { - backend = "s3" - - config = { - skip_credentials_validation = true - skip_metadata_api_check = true - access_key = var.spaces_access_id - secret_key = var.spaces_secret_key - region = "us-east-1" - endpoint = "nyc3.digitaloceanspaces.com" - bucket = "jdormit-tf-state" - key = "mgmt/do-ssh-keys.tfstate" - } -} - -data "local_file" "packer_manifest" { - filename = "${path.module}/../packer/packer-manifest.json" -} - -locals { - packer_manifest = jsondecode(data.local_file.packer_manifest.content) - packer_builds = local.packer_manifest.builds - packer_image_str = element(local.packer_builds, length(local.packer_builds) - 1).artifact_id - packer_image = split(":", local.packer_image_str)[1] -} - -resource "digitalocean_droplet" "syncthing" { - name = "syncthing" - image = local.packer_image - region = "nyc1" - size = "s-1vcpu-1gb" - backups = true - volume_ids = [digitalocean_volume.syncthing_volume.id] - ssh_keys = [ - data.terraform_remote_state.do_ssh_keys.outputs.jdormit_laptop_ssh_key_id, - data.terraform_remote_state.do_ssh_keys.outputs.jdormit_macbook_lola_ssh_key_id - ] -} - -resource "digitalocean_volume" "syncthing_volume" { - name = "syncthing-volume" - description = "The volume to hold the default Sync folder" - region = "nyc1" - size = 100 - initial_filesystem_label = "syncthing-volume" - initial_filesystem_type = "ext4" - - lifecycle { - prevent_destroy = true - } -} diff --git a/prod/syncthing-packer/terraform/outputs.tf b/prod/syncthing-packer/terraform/outputs.tf deleted file mode 100644 index cc7cf3f..0000000 --- a/prod/syncthing-packer/terraform/outputs.tf +++ /dev/null @@ -1,11 +0,0 @@ -output "ip_address" { - value = digitalocean_droplet.syncthing.ipv4_address -} - -output "urn" { - value = digitalocean_droplet.syncthing.urn -} - -output "volume_urn" { - value = digitalocean_volume.syncthing_volume.urn -} diff --git a/prod/syncthing-packer/terraform/terraform.tf b/prod/syncthing-packer/terraform/terraform.tf deleted file mode 100644 index 2e7bd6a..0000000 --- a/prod/syncthing-packer/terraform/terraform.tf +++ /dev/null @@ -1,18 +0,0 @@ -terraform { - required_providers { - digitalocean = { - source = "digitalocean/digitalocean" - version = "~> 2.3.0" - } - } - - backend "s3" { - skip_credentials_validation = true - skip_metadata_api_check = true - # Need to specify an AWS region to stop Terraform complaining - region = "us-east-1" - endpoint = "nyc3.digitaloceanspaces.com" - bucket = "jdormit-tf-state" - key = "prod/syncthing-packer.tfstate" - } -} diff --git a/prod/syncthing-packer/terraform/variables.tf b/prod/syncthing-packer/terraform/variables.tf deleted file mode 100644 index 1b3748a..0000000 --- a/prod/syncthing-packer/terraform/variables.tf +++ /dev/null @@ -1,11 +0,0 @@ -variable "do_token" { - type = string -} - -variable "spaces_access_id" { - type = string -} - -variable "spaces_secret_key" { - type = string -} diff --git a/prod/syncthing-packer/.gitignore b/prod/syncthing/.gitignore similarity index 100% rename from prod/syncthing-packer/.gitignore rename to prod/syncthing/.gitignore diff --git a/prod/syncthing/ansible/.envrc b/prod/syncthing/ansible/.envrc deleted file mode 100644 index 0512d72..0000000 --- a/prod/syncthing/ansible/.envrc +++ /dev/null @@ -1 +0,0 @@ -export ANSIBLE_INVENTORY="$(expand_path hosts.ini)" diff --git a/prod/syncthing/ansible/hosts.ini b/prod/syncthing/ansible/hosts.ini deleted file mode 100644 index 3ef82f9..0000000 --- a/prod/syncthing/ansible/hosts.ini +++ /dev/null @@ -1 +0,0 @@ -syncthing.jeremydormitzer.com \ No newline at end of file diff --git a/prod/syncthing-packer/packer/Makefile b/prod/syncthing/packer/Makefile similarity index 100% rename from prod/syncthing-packer/packer/Makefile rename to prod/syncthing/packer/Makefile diff --git a/prod/syncthing-packer/packer/do.ini.template b/prod/syncthing/packer/do.ini.template similarity index 100% rename from prod/syncthing-packer/packer/do.ini.template rename to prod/syncthing/packer/do.ini.template diff --git a/prod/syncthing-packer/packer/packer-manifest.json b/prod/syncthing/packer/packer-manifest.json similarity index 100% rename from prod/syncthing-packer/packer/packer-manifest.json rename to prod/syncthing/packer/packer-manifest.json diff --git a/prod/syncthing-packer/packer/syncthing-cert.pem.template b/prod/syncthing/packer/syncthing-cert.pem.template similarity index 100% rename from prod/syncthing-packer/packer/syncthing-cert.pem.template rename to prod/syncthing/packer/syncthing-cert.pem.template diff --git a/prod/syncthing-packer/packer/syncthing-config.xml.template b/prod/syncthing/packer/syncthing-config.xml.template similarity index 100% rename from prod/syncthing-packer/packer/syncthing-config.xml.template rename to prod/syncthing/packer/syncthing-config.xml.template diff --git a/prod/syncthing-packer/packer/syncthing-key.pem.template b/prod/syncthing/packer/syncthing-key.pem.template similarity index 100% rename from prod/syncthing-packer/packer/syncthing-key.pem.template rename to prod/syncthing/packer/syncthing-key.pem.template diff --git a/prod/syncthing-packer/packer/syncthing.conf b/prod/syncthing/packer/syncthing.conf similarity index 100% rename from prod/syncthing-packer/packer/syncthing.conf rename to prod/syncthing/packer/syncthing.conf diff --git a/prod/syncthing-packer/packer/syncthing.json b/prod/syncthing/packer/syncthing.json similarity index 100% rename from prod/syncthing-packer/packer/syncthing.json rename to prod/syncthing/packer/syncthing.json diff --git a/prod/syncthing-packer/packer/syncthing@.service b/prod/syncthing/packer/syncthing@.service similarity index 100% rename from prod/syncthing-packer/packer/syncthing@.service rename to prod/syncthing/packer/syncthing@.service diff --git a/prod/syncthing-packer/terraform/.terraform.lock.hcl b/prod/syncthing/terraform/.terraform.lock.hcl similarity index 100% rename from prod/syncthing-packer/terraform/.terraform.lock.hcl rename to prod/syncthing/terraform/.terraform.lock.hcl diff --git a/prod/syncthing/terraform/main.tf b/prod/syncthing/terraform/main.tf index 8fa079d..82e7676 100644 --- a/prod/syncthing/terraform/main.tf +++ b/prod/syncthing/terraform/main.tf @@ -4,17 +4,54 @@ provider "digitalocean" { spaces_secret_key = var.spaces_secret_key } -resource "digitalocean_droplet" "jdormit_syncthing" { - name = "jdormit-syncthing" - image = "53893572" +data "terraform_remote_state" "do_ssh_keys" { + backend = "s3" + + config = { + skip_credentials_validation = true + skip_metadata_api_check = true + access_key = var.spaces_access_id + secret_key = var.spaces_secret_key + region = "us-east-1" + endpoint = "nyc3.digitaloceanspaces.com" + bucket = "jdormit-tf-state" + key = "mgmt/do-ssh-keys.tfstate" + } +} + +data "local_file" "packer_manifest" { + filename = "${path.module}/../packer/packer-manifest.json" +} + +locals { + packer_manifest = jsondecode(data.local_file.packer_manifest.content) + packer_builds = local.packer_manifest.builds + packer_image_str = element(local.packer_builds, length(local.packer_builds) - 1).artifact_id + packer_image = split(":", local.packer_image_str)[1] +} + +resource "digitalocean_droplet" "syncthing" { + name = "syncthing" + image = local.packer_image region = "nyc1" size = "s-1vcpu-1gb" backups = true volume_ids = [digitalocean_volume.syncthing_volume.id] + ssh_keys = [ + data.terraform_remote_state.do_ssh_keys.outputs.jdormit_laptop_ssh_key_id, + data.terraform_remote_state.do_ssh_keys.outputs.jdormit_macbook_lola_ssh_key_id + ] } resource "digitalocean_volume" "syncthing_volume" { - name = "volume-nyc1-01" - region = "nyc1" - size = 100 + name = "syncthing-volume" + description = "The volume to hold the default Sync folder" + region = "nyc1" + size = 100 + initial_filesystem_label = "syncthing-volume" + initial_filesystem_type = "ext4" + + lifecycle { + prevent_destroy = true + } } diff --git a/prod/syncthing/terraform/outputs.tf b/prod/syncthing/terraform/outputs.tf index d2e5b96..cc7cf3f 100644 --- a/prod/syncthing/terraform/outputs.tf +++ b/prod/syncthing/terraform/outputs.tf @@ -1,11 +1,11 @@ -output "syncthing_ip_address" { - value = digitalocean_droplet.jdormit_syncthing.ipv4_address +output "ip_address" { + value = digitalocean_droplet.syncthing.ipv4_address } -output "syncthing_urn" { - value = digitalocean_droplet.jdormit_syncthing.urn +output "urn" { + value = digitalocean_droplet.syncthing.urn } -output "syncthing_volume_urn" { +output "volume_urn" { value = digitalocean_volume.syncthing_volume.urn } diff --git a/prod/syncthing/terraform/terraform.tf b/prod/syncthing/terraform/terraform.tf index 8f7e5a7..2e7bd6a 100644 --- a/prod/syncthing/terraform/terraform.tf +++ b/prod/syncthing/terraform/terraform.tf @@ -13,6 +13,6 @@ terraform { region = "us-east-1" endpoint = "nyc3.digitaloceanspaces.com" bucket = "jdormit-tf-state" - key = "prod/syncthing.tfstate" + key = "prod/syncthing-packer.tfstate" } }