diff --git a/infra/load-balancer.tf b/infra/load-balancer.tf index 21956c9..683b1c6 100644 --- a/infra/load-balancer.tf +++ b/infra/load-balancer.tf @@ -21,14 +21,13 @@ resource "aws_lb" "alpha" { ## target group so we only need to provide the pool ##################################################################### resource "aws_lb_target_group" "nginx" { - for_each = toset(local.buckets) - name = "${var.athens_prefix}-${replace(each.value, ".", "-")}" + name = local.nginx_name port = var.nginx_port protocol = "HTTP" target_type = "ip" vpc_id = aws_vpc.athens_vpc.id health_check { - interval = 120 + interval = local.nginx_hp_check_interval } } @@ -65,19 +64,15 @@ resource "aws_lb_listener" "https" { } resource "aws_lb_listener_rule" "beta" { - for_each = { - for index, record in local.buckets: - index => record - } listener_arn = aws_lb_listener.https.arn - priority = 100 + each.key + priority = 100 action { type = "forward" - target_group_arn = aws_lb_target_group.nginx[each.value].arn + target_group_arn = aws_lb_target_group.nginx.arn } condition { host_header { - values = [ each.value ] + values = local.buckets } } } diff --git a/infra/local.tf b/infra/local.tf index 4349106..2eb5d6c 100644 --- a/infra/local.tf +++ b/infra/local.tf @@ -3,5 +3,11 @@ locals { repos = [ "reverse-proxy", ] + buckets = [ + "shockrah.xyz", + "resume.shockrah.xyz" + ] + nginx_name = "${var.athens_prefix}-nginx-static-content" + nginx_hp_check_interval = 300 } diff --git a/infra/nginx.tf b/infra/nginx.tf index 84a007b..69b4de6 100644 --- a/infra/nginx.tf +++ b/infra/nginx.tf @@ -1,8 +1,4 @@ -# This nginx service will replace the beta host so that -# we leverage nginx as a reverse proxy in fargate instead - resource "aws_ecs_task_definition" "beta" { - for_each = toset(local.buckets) family = "${var.athens_prefix}-beta" network_mode = "awsvpc" @@ -14,18 +10,11 @@ resource "aws_ecs_task_definition" "beta" { container_definitions = jsonencode([ { - name = "${var.athens_prefix}-${replace(each.value, ".", "-")}" + name = local.nginx_name image = "805875567437.dkr.ecr.us-west-1.amazonaws.com/reverse-proxy:latest" cpu = 256 memory = 512 essential = true - environment = [ - { name = "S3_ACCESS_KEY_ID", value = var.shockrah_xyz_s3_access_key_id }, - { name = "S3_SECRET_KEY", value = var.shockrah_xyz_s3_secret_key }, - { name = "S3_REGION", value = var.aws_region }, - { name = "S3_SERVER", value = "s3-${var.aws_region}.amazonaws.com" }, - { name = "S3_BUCKET_NAME", value = each.value }, - ] portMappings = [ { containerPort = var.nginx_port, @@ -49,16 +38,14 @@ resource "aws_ecs_task_definition" "beta" { } resource "aws_ecs_service" "beta_reverse_proxy" { - for_each = toset(local.buckets) - - name = "${var.athens_prefix}-proxy-${replace(each.value, ".", "-")}" + name = local.nginx_name cluster = aws_ecs_cluster.alpha.id - task_definition = aws_ecs_task_definition.beta[each.value].arn + task_definition = aws_ecs_task_definition.beta.arn desired_count = 1 launch_type = "FARGATE" load_balancer { - target_group_arn = aws_lb_target_group.nginx[each.value].arn - container_name = "${var.athens_prefix}-${replace(each.value, ".", "-")}" + target_group_arn = aws_lb_target_group.nginx.arn + container_name = local.nginx_name container_port = var.nginx_port } diff --git a/infra/s3.tf b/infra/s3.tf index 2850575..bed30f2 100644 --- a/infra/s3.tf +++ b/infra/s3.tf @@ -1,10 +1,3 @@ -locals { - buckets = [ - "shockrah.xyz", - "resume.shockrah.xyz" - ] -} - resource "aws_s3_bucket" "static-content" { for_each = { for idx, record in local.buckets: