From aec886064a1bf78ff113e5564fefc716f5cf0ac1 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Mon, 4 Oct 2021 09:28:06 -0400 Subject: [PATCH] [WIP] Add actual server values to nginx conf --- prod/nginx/packer/terraform/data.tf | 59 +++++++++++++++++++ prod/nginx/packer/terraform/main.tf | 28 ++++++++- .../terraform/templates/nginx.conf.template | 11 +++- prod/nginx/packer/terraform/variables.tf | 11 ++++ 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 prod/nginx/packer/terraform/data.tf create mode 100644 prod/nginx/packer/terraform/variables.tf diff --git a/prod/nginx/packer/terraform/data.tf b/prod/nginx/packer/terraform/data.tf new file mode 100644 index 0000000..e0685bd --- /dev/null +++ b/prod/nginx/packer/terraform/data.tf @@ -0,0 +1,59 @@ +data "terraform_remote_state" "gitea" { + 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/gitea.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" "wallabag" { + 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/wallabag.tfstate" + } +} + +data "terraform_remote_state" "freshrss" { + 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/freshrss.tfstate" + } +} diff --git a/prod/nginx/packer/terraform/main.tf b/prod/nginx/packer/terraform/main.tf index 7e5d38c..8ea4308 100644 --- a/prod/nginx/packer/terraform/main.tf +++ b/prod/nginx/packer/terraform/main.tf @@ -1,4 +1,30 @@ resource "local_file" "nginx_config" { filename = "${path.module}/../tmp/nginx.conf" - content = templatefile("${path.module}/templates/nginx.conf.template", {}) + content = templatefile( + "${path.module}/templates/nginx.conf.template", + { + "servers" : [ + { + "domain" : "git.jeremydormitzer.com", + "ip" : "${data.terraform_remote_state.gitea.outputs.gitea_ip_address}", + "port" : "3000" + }, + { + "domain" : "wallabag.jeremydormitzer.com", + "ip" : "${data.terraform_remote_state.wallabag.outputs.ip_address}", + "port" : "80" + }, + { + "domain" : "rss.jeremydormitzer.com", + "ip" : "${data.terraform_remote_state.freshrss.outputs.ip_address}", + "port" : "80" + }, + { + "domain" : "syncthing.jeremydormitzer.com", + "ip" : "${data.terraform_remote_state.syncthing.outputs.ip_address}", + "port" : "8384" + } + ] + } + ) } diff --git a/prod/nginx/packer/terraform/templates/nginx.conf.template b/prod/nginx/packer/terraform/templates/nginx.conf.template index 30d74d2..a7af42b 100644 --- a/prod/nginx/packer/terraform/templates/nginx.conf.template +++ b/prod/nginx/packer/terraform/templates/nginx.conf.template @@ -1 +1,10 @@ -test \ No newline at end of file +%{ for server in servers ~} +server { + server_name ${server.domain} + + location / { + proxy_pass http://${server.ip}:${server.port} + } +} + +%{ endfor ~} \ No newline at end of file diff --git a/prod/nginx/packer/terraform/variables.tf b/prod/nginx/packer/terraform/variables.tf new file mode 100644 index 0000000..1b3748a --- /dev/null +++ b/prod/nginx/packer/terraform/variables.tf @@ -0,0 +1,11 @@ +variable "do_token" { + type = string +} + +variable "spaces_access_id" { + type = string +} + +variable "spaces_secret_key" { + type = string +}