From 2770cf543915afde2632800695e82ed4a5bdfe95 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 3 Dec 2020 22:49:00 -0500 Subject: [PATCH] Pull jdormit-website ip address from remote state --- mgmt/do-jeremydormitzer-com/main.tf | 21 ++++++++++++++++++--- prod/jdormit-website/main.tf | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mgmt/do-jeremydormitzer-com/main.tf b/mgmt/do-jeremydormitzer-com/main.tf index 271a1da..ac7b8b2 100644 --- a/mgmt/do-jeremydormitzer-com/main.tf +++ b/mgmt/do-jeremydormitzer-com/main.tf @@ -4,6 +4,21 @@ 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" + } +} + # This domain is registered via Google Domains, so the nameservers # there need to point to DO's nameservers resource "digitalocean_domain" "jeremydormitzer_com" { @@ -17,7 +32,7 @@ resource "digitalocean_record" "top_level_a" { domain = digitalocean_domain.jeremydormitzer_com.name type = "A" name = "@" - value = "67.205.191.63" + value = data.terraform_remote_state.jdormit_website.outputs.jdormit_website_ip_address ttl = 3600 } @@ -25,7 +40,7 @@ resource "digitalocean_record" "www" { domain = digitalocean_domain.jeremydormitzer_com.name type = "A" name = "www" - value = "67.205.191.63" + value = data.terraform_remote_state.jdormit_website.outputs.jdormit_website_ip_address ttl = 3600 } @@ -91,6 +106,6 @@ resource "digitalocean_record" "wallabag" { domain = digitalocean_domain.jeremydormitzer_com.name type = "A" name = "wallabag" - value = "67.205.191.63" + value = data.terraform_remote_state.jdormit_website.outputs.jdormit_website_ip_address ttl = 3600 } diff --git a/prod/jdormit-website/main.tf b/prod/jdormit-website/main.tf index 83be765..a94fa4b 100644 --- a/prod/jdormit-website/main.tf +++ b/prod/jdormit-website/main.tf @@ -11,3 +11,7 @@ resource "digitalocean_droplet" "jdormit_website" { size = "s-1vcpu-1gb" backups = true } + +output "jdormit_website_ip_address" { + value = digitalocean_droplet.jdormit_website.ipv4_address +}