From 3db3fa23998972cd17e821a4150d4a3672b9664b Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Fri, 4 Dec 2020 07:15:55 -0500 Subject: [PATCH] Pull remaining droplet IPs from remote state --- mgmt/do-jeremydormitzer-com/main.tf | 37 ++++++++++++++++++++++++---- prod/git-jeremydormitzer-com/main.tf | 4 +++ prod/syncthing/main.tf | 4 +++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/mgmt/do-jeremydormitzer-com/main.tf b/mgmt/do-jeremydormitzer-com/main.tf index ac7b8b2..1753f35 100644 --- a/mgmt/do-jeremydormitzer-com/main.tf +++ b/mgmt/do-jeremydormitzer-com/main.tf @@ -19,15 +19,42 @@ data "terraform_remote_state" "jdormit_website" { } } +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" { name = "jeremydormitzer.com" } -# TODO once these services are managed by Terraform, update the IP -# addresses to pull from Terraform state - resource "digitalocean_record" "top_level_a" { domain = digitalocean_domain.jeremydormitzer_com.name type = "A" @@ -64,7 +91,7 @@ resource "digitalocean_record" "git" { domain = digitalocean_domain.jeremydormitzer_com.name type = "A" name = "git" - value = "159.203.78.16" + value = data.terraform_remote_state.git_jeremydormitzer_com.outputs.git_ip_address ttl = 3600 } @@ -98,7 +125,7 @@ resource "digitalocean_record" "syncthing" { domain = digitalocean_domain.jeremydormitzer_com.name type = "A" name = "syncthing" - value = "198.199.86.10" + value = data.terraform_remote_state.syncthing.outputs.syncthing_ip_address ttl = 3600 } diff --git a/prod/git-jeremydormitzer-com/main.tf b/prod/git-jeremydormitzer-com/main.tf index 119822f..c352147 100644 --- a/prod/git-jeremydormitzer-com/main.tf +++ b/prod/git-jeremydormitzer-com/main.tf @@ -11,3 +11,7 @@ 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/syncthing/main.tf b/prod/syncthing/main.tf index 8fa079d..ec37c4e 100644 --- a/prod/syncthing/main.tf +++ b/prod/syncthing/main.tf @@ -18,3 +18,7 @@ resource "digitalocean_volume" "syncthing_volume" { region = "nyc1" size = 100 } + +output "syncthing_ip_address" { + value = digitalocean_droplet.jdormit_syncthing.ipv4_address +}