From d720513ca1059a0a6af18a2f5702710cca4d995f Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Thu, 26 Sep 2024 11:55:12 +0300 Subject: [PATCH] TF config fixes --- stun_server/outputs.tf | 16 +++++++++++++--- stun_server/region/dns.tf | 2 +- stun_server/region/ecs.tf | 6 +++--- stun_server/region/module.tf | 2 +- stun_server/region/network.tf | 2 +- stun_server/region/outputs.tf | 4 ++++ stun_server/region/versions.tf | 19 +++++++++++++++++++ stun_server/versions.tf | 10 ---------- 8 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 stun_server/region/outputs.tf create mode 100644 stun_server/region/versions.tf diff --git a/stun_server/outputs.tf b/stun_server/outputs.tf index e32a571..c93c4c8 100644 --- a/stun_server/outputs.tf +++ b/stun_server/outputs.tf @@ -1,4 +1,14 @@ -output "stun_server_ip" { - description = "The public IP address of the stun server" - value = data.aws_network_interface.stun_server_interface.association[0].public_ip +output "stun_server_ip-us_east_1" { + description = "The public IP address of the stun server in us-east-1" + value = module.us_east_1.stun_server_ip +} + +output "stun_server_ip-eu_central_1" { + description = "The public IP address of the stun server in eu-central-1" + value = module.eu_central_1.stun_server_ip +} + +output "stun_server_ip-ap_southeast_1" { + description = "The public IP address of the stun server in ap-southeast-1" + value = module.ap_southeast_1.stun_server_ip } diff --git a/stun_server/region/dns.tf b/stun_server/region/dns.tf index cc6f238..8853183 100644 --- a/stun_server/region/dns.tf +++ b/stun_server/region/dns.tf @@ -5,7 +5,7 @@ data "cloudflare_zone" "dns_zone" { resource "cloudflare_record" "instance_dns" { zone_id = data.cloudflare_zone.dns_zone.id name = join("-", [var.subdomain, data.aws_region.current.name]) - content = module.stun_server.aws_network_interface.stun_server_interface.association[0].public_ip + content = data.aws_network_interface.stun_server_interface.association[0].public_ip type = "A" proxied = true } diff --git a/stun_server/region/ecs.tf b/stun_server/region/ecs.tf index 6a1028a..661b94b 100644 --- a/stun_server/region/ecs.tf +++ b/stun_server/region/ecs.tf @@ -1,6 +1,6 @@ resource "aws_ecs_service" "stun-server" { name = local.service_name - cluster = data.tfe_outputs.infrastructure.values[aws_region.current.name].ecs_cluster + cluster = data.tfe_outputs.infrastructure.values[data.aws_region.current.name].ecs_cluster task_definition = module.stun_server.task_definition desired_count = 1 deployment_minimum_healthy_percent = 100 @@ -16,8 +16,8 @@ resource "aws_ecs_service" "stun-server" { assign_public_ip = true security_groups = [aws_security_group.stun_sg.id] subnets = [ - data.tfe_outputs.infrastructure.values.public_subnets[0], - data.tfe_outputs.infrastructure.values.public_subnets[1] + data.tfe_outputs.infrastructure.values[data.aws_region.current.name].public_subnets[0], + data.tfe_outputs.infrastructure.values[data.aws_region.current.name].public_subnets[1] ] } } diff --git a/stun_server/region/module.tf b/stun_server/region/module.tf index 57f5ab1..de5b257 100644 --- a/stun_server/region/module.tf +++ b/stun_server/region/module.tf @@ -20,7 +20,7 @@ module "stun_server" { service_name = local.service_name container_image = "ghcr.io/home-assistant/stun" container_version = var.image_tag - region = aws_region.current.name + region = data.aws_region.current.name ecs_cpu = 2048 ecs_memory = 4096 container_definitions = { diff --git a/stun_server/region/network.tf b/stun_server/region/network.tf index 6cd37b4..c62490e 100644 --- a/stun_server/region/network.tf +++ b/stun_server/region/network.tf @@ -1,5 +1,5 @@ resource "aws_security_group" "stun_sg" { - vpc_id = data.tfe_outputs.infrastructure.values[aws_region.current.name].network_id + vpc_id = data.tfe_outputs.infrastructure.values[data.aws_region.current.name].network_id egress { from_port = 0 diff --git a/stun_server/region/outputs.tf b/stun_server/region/outputs.tf new file mode 100644 index 0000000..e32a571 --- /dev/null +++ b/stun_server/region/outputs.tf @@ -0,0 +1,4 @@ +output "stun_server_ip" { + description = "The public IP address of the stun server" + value = data.aws_network_interface.stun_server_interface.association[0].public_ip +} diff --git a/stun_server/region/versions.tf b/stun_server/region/versions.tf new file mode 100644 index 0000000..f019d63 --- /dev/null +++ b/stun_server/region/versions.tf @@ -0,0 +1,19 @@ +terraform { + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.0" + } + + tfe = { + source = "hashicorp/tfe" + version = "~> 0.58.0" + } + + cloudflare = { + source = "cloudflare/cloudflare" + version = "~> 4.0" + } + } +} diff --git a/stun_server/versions.tf b/stun_server/versions.tf index f9a7eb1..89ae572 100644 --- a/stun_server/versions.tf +++ b/stun_server/versions.tf @@ -6,15 +6,5 @@ terraform { source = "hashicorp/aws" version = "~> 4.0" } - - tfe = { - source = "hashicorp/tfe" - version = "~> 0.58.0" - } - - cloudflare = { - source = "cloudflare/cloudflare" - version = "~> 4.0" - } } }