From cabad59c81d607d13aadf74a695c0d4527bcc6df Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Fri, 4 Dec 2020 09:10:23 -0500 Subject: [PATCH] Load project resources from terraform remote state --- mgmt/do-jeremydormitzer-com/data.tf | 44 +++++++++++++++ mgmt/do-jeremydormitzer-com/main.tf | 45 --------------- mgmt/do-jeremydormitzer-com/outputs.tf | 3 + mgmt/do-project-jeremydormitzer/data.tf | 74 +++++++++++++++++++++++++ mgmt/do-project-jeremydormitzer/main.tf | 8 +++ prod/git-jeremydormitzer-com/main.tf | 4 -- prod/git-jeremydormitzer-com/outputs.tf | 7 +++ prod/jdormit-website/main.tf | 4 -- prod/jdormit-website/outputs.tf | 7 +++ prod/justin-ghost-site/outputs.tf | 3 + prod/syncthing/main.tf | 4 -- prod/syncthing/outputs.tf | 11 ++++ 12 files changed, 157 insertions(+), 57 deletions(-) create mode 100644 mgmt/do-jeremydormitzer-com/data.tf create mode 100644 mgmt/do-jeremydormitzer-com/outputs.tf create mode 100644 mgmt/do-project-jeremydormitzer/data.tf create mode 100644 prod/git-jeremydormitzer-com/outputs.tf create mode 100644 prod/jdormit-website/outputs.tf create mode 100644 prod/justin-ghost-site/outputs.tf create mode 100644 prod/syncthing/outputs.tf diff --git a/mgmt/do-jeremydormitzer-com/data.tf b/mgmt/do-jeremydormitzer-com/data.tf new file mode 100644 index 0000000..c1700b4 --- /dev/null +++ b/mgmt/do-jeremydormitzer-com/data.tf @@ -0,0 +1,44 @@ +data "terraform_remote_state" "jdormit_website" { + 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 = "prod/jdormit-website.tfstate" + } +} + +data "terraform_remote_state" "git_jeremydormitzer_com" { + 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 = "prod/git-jeremydormitzer-com.tfstate" + } +} + +data "terraform_remote_state" "syncthing" { + 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 = "prod/syncthing.tfstate" + } +} diff --git a/mgmt/do-jeremydormitzer-com/main.tf b/mgmt/do-jeremydormitzer-com/main.tf index 1753f35..e2b8ca9 100644 --- a/mgmt/do-jeremydormitzer-com/main.tf +++ b/mgmt/do-jeremydormitzer-com/main.tf @@ -4,51 +4,6 @@ provider "digitalocean" { spaces_secret_key = var.spaces_secret_key } -data "terraform_remote_state" "jdormit_website" { - 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 = "prod/jdormit-website.tfstate" - } -} - -data "terraform_remote_state" "git_jeremydormitzer_com" { - 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 = "prod/git-jeremydormitzer-com.tfstate" - } -} - -data "terraform_remote_state" "syncthing" { - 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 = "prod/syncthing.tfstate" - } -} - # This domain is registered via Google Domains, so the nameservers # there need to point to DO's nameservers resource "digitalocean_domain" "jeremydormitzer_com" { diff --git a/mgmt/do-jeremydormitzer-com/outputs.tf b/mgmt/do-jeremydormitzer-com/outputs.tf new file mode 100644 index 0000000..51d6e6f --- /dev/null +++ b/mgmt/do-jeremydormitzer-com/outputs.tf @@ -0,0 +1,3 @@ +output "jeremydormitzer_com_urn" { + value = digitalocean_domain.jeremydormitzer_com.urn +} diff --git a/mgmt/do-project-jeremydormitzer/data.tf b/mgmt/do-project-jeremydormitzer/data.tf new file mode 100644 index 0000000..9c59f0e --- /dev/null +++ b/mgmt/do-project-jeremydormitzer/data.tf @@ -0,0 +1,74 @@ +data "terraform_remote_state" "jdormit_website" { + 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 = "prod/jdormit-website.tfstate" + } +} + +data "terraform_remote_state" "git_jeremydormitzer_com" { + 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 = "prod/git-jeremydormitzer-com.tfstate" + } +} + +data "terraform_remote_state" "syncthing" { + 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 = "prod/syncthing.tfstate" + } +} + +data "terraform_remote_state" "justin_ghost_site" { + 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 = "prod/justin-ghost-site.tfstate" + } +} + +data "terraform_remote_state" "jeremydormitzer_com" { + 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-dns.tfstate" + } +} diff --git a/mgmt/do-project-jeremydormitzer/main.tf b/mgmt/do-project-jeremydormitzer/main.tf index 013158d..44c5af1 100644 --- a/mgmt/do-project-jeremydormitzer/main.tf +++ b/mgmt/do-project-jeremydormitzer/main.tf @@ -9,4 +9,12 @@ resource "digitalocean_project" "jeremy_dormitzer" { environment = "Production" description = "Personal infrastructure" purpose = "Personal infrastructure" + resources = [ + data.terraform_remote_state.jdormit_website.outputs.jdormit_website_urn, + data.terraform_remote_state.git_jeremydormitzer_com.outputs.git_urn, + data.terraform_remote_state.syncthing.outputs.syncthing_urn, + data.terraform_remote_state.syncthing.outputs.syncthing_volume_urn, + data.terraform_remote_state.justin_ghost_site.outputs.justin_ghost_site_urn, + data.terraform_remote_state.jeremydormitzer_com.outputs.jeremydormitzer_com_urn + ] } diff --git a/prod/git-jeremydormitzer-com/main.tf b/prod/git-jeremydormitzer-com/main.tf index c352147..119822f 100644 --- a/prod/git-jeremydormitzer-com/main.tf +++ b/prod/git-jeremydormitzer-com/main.tf @@ -11,7 +11,3 @@ resource "digitalocean_droplet" "git_jeremydormitzer_com" { size = "s-1vcpu-1gb" backups = true } - -output "git_ip_address" { - value = digitalocean_droplet.git_jeremydormitzer_com.ipv4_address -} diff --git a/prod/git-jeremydormitzer-com/outputs.tf b/prod/git-jeremydormitzer-com/outputs.tf new file mode 100644 index 0000000..2954a17 --- /dev/null +++ b/prod/git-jeremydormitzer-com/outputs.tf @@ -0,0 +1,7 @@ +output "git_ip_address" { + value = digitalocean_droplet.git_jeremydormitzer_com.ipv4_address +} + +output "git_urn" { + value = digitalocean_droplet.git_jeremydormitzer_com.urn +} diff --git a/prod/jdormit-website/main.tf b/prod/jdormit-website/main.tf index a94fa4b..83be765 100644 --- a/prod/jdormit-website/main.tf +++ b/prod/jdormit-website/main.tf @@ -11,7 +11,3 @@ resource "digitalocean_droplet" "jdormit_website" { size = "s-1vcpu-1gb" backups = true } - -output "jdormit_website_ip_address" { - value = digitalocean_droplet.jdormit_website.ipv4_address -} diff --git a/prod/jdormit-website/outputs.tf b/prod/jdormit-website/outputs.tf new file mode 100644 index 0000000..52fadf6 --- /dev/null +++ b/prod/jdormit-website/outputs.tf @@ -0,0 +1,7 @@ +output "jdormit_website_ip_address" { + value = digitalocean_droplet.jdormit_website.ipv4_address +} + +output "jdormit_website_urn" { + value = digitalocean_droplet.jdormit_website.urn +} diff --git a/prod/justin-ghost-site/outputs.tf b/prod/justin-ghost-site/outputs.tf new file mode 100644 index 0000000..356be92 --- /dev/null +++ b/prod/justin-ghost-site/outputs.tf @@ -0,0 +1,3 @@ +output "justin_ghost_site_urn" { + value = digitalocean_droplet.justin_ghost_site.urn +} diff --git a/prod/syncthing/main.tf b/prod/syncthing/main.tf index ec37c4e..8fa079d 100644 --- a/prod/syncthing/main.tf +++ b/prod/syncthing/main.tf @@ -18,7 +18,3 @@ resource "digitalocean_volume" "syncthing_volume" { region = "nyc1" size = 100 } - -output "syncthing_ip_address" { - value = digitalocean_droplet.jdormit_syncthing.ipv4_address -} diff --git a/prod/syncthing/outputs.tf b/prod/syncthing/outputs.tf new file mode 100644 index 0000000..d2e5b96 --- /dev/null +++ b/prod/syncthing/outputs.tf @@ -0,0 +1,11 @@ +output "syncthing_ip_address" { + value = digitalocean_droplet.jdormit_syncthing.ipv4_address +} + +output "syncthing_urn" { + value = digitalocean_droplet.jdormit_syncthing.urn +} + +output "syncthing_volume_urn" { + value = digitalocean_volume.syncthing_volume.urn +}