Skip to content

Commit

Permalink
Code improvements based on PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Sep 26, 2024
1 parent 05e8f2b commit 967087c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 28 deletions.
3 changes: 0 additions & 3 deletions stun_server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module "us_east_1" {

region = "us-east-1"
domain_name = var.domain_name
subdomain = "stun"
image_tag = var.image_tag
}

Expand All @@ -26,7 +25,6 @@ module "eu_central_1" {

region = "eu-central-1"
domain_name = var.domain_name
subdomain = "stun"
image_tag = var.image_tag
}

Expand All @@ -35,6 +33,5 @@ module "ap_southeast_1" {

region = "ap-southeast-1"
domain_name = var.domain_name
subdomain = "stun"
image_tag = var.image_tag
}
20 changes: 7 additions & 13 deletions stun_server/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
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
output "stun_server_ip" {
description = "The public IP address of the stun server"
value = {
"us-east-1" = module.us_east_1.stun_server_ip
"eu-central-1" = module.eu_central_1.stun_server_ip
"ap-southeast-1" = module.ap_southeast_1.stun_server_ip
}
}
2 changes: 1 addition & 1 deletion stun_server/region/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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])
name = join("-", ["stun", data.aws_region.current.name])
content = data.aws_network_interface.stun_server_interface.association[0].public_ip
type = "A"
proxied = true
Expand Down
8 changes: 4 additions & 4 deletions stun_server/region/ecs.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
resource "aws_ecs_service" "stun-server" {
name = local.service_name
cluster = data.tfe_outputs.infrastructure.values[data.aws_region.current.name].ecs_cluster
cluster = locals.infrastructure_region_outputs.ecs_cluster
task_definition = module.stun_server.task_definition
desired_count = 1
deployment_minimum_healthy_percent = 100
deployment_maximum_percent = 200
health_check_grace_period_seconds = 90
launch_type = local.launch_type
launch_type = "FARGATE"

# Required to fetch the public IP address of the ECS service
enable_ecs_managed_tags = true
Expand All @@ -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[data.aws_region.current.name].public_subnets[0],
data.tfe_outputs.infrastructure.values[data.aws_region.current.name].public_subnets[1]
locals.infrastructure_region_outputs.public_subnets[0],
locals.infrastructure_region_outputs.public_subnets[1]
]
}

Expand Down
4 changes: 2 additions & 2 deletions stun_server/region/module.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
service_name = "stun-server"
launch_type = "FARGATE"
service_name = "stun-server"
infrastructure_region_outputs = data.tfe_outputs.infrastructure.values[data.aws_region.current.name]
}

provider "aws" {
Expand Down
2 changes: 1 addition & 1 deletion stun_server/region/network.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_security_group" "stun_sg" {
vpc_id = data.tfe_outputs.infrastructure.values[data.aws_region.current.name].network_id
vpc_id = locals.infrastructure_region_outputs.network_id

egress {
from_port = 0
Expand Down
4 changes: 0 additions & 4 deletions stun_server/region/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ variable "domain_name" {
type = string
}

variable "subdomain" {
description = "The subdomain to use for the STUN server"
type = string
}
variable "image_tag" {
description = "Version of the Stun server to deploy"
type = string
Expand Down

0 comments on commit 967087c

Please sign in to comment.