From 2a8d178773d1ec3b2cbae5bac4f1da99ba6a4963 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 10 Nov 2023 12:35:08 -0500 Subject: [PATCH] fix: Ensure conditional creation of EFS and entire module are functioning as intended (#370) --- examples/github-separate/README.md | 1 + examples/github-separate/main.tf | 22 ++++++---------------- main.tf | 6 +++--- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/examples/github-separate/README.md b/examples/github-separate/README.md index db88f678..7643a023 100644 --- a/examples/github-separate/README.md +++ b/examples/github-separate/README.md @@ -37,6 +37,7 @@ Note that this example may create resources which cost money. Run `terraform des |------|--------|---------| | [alb](#module\_alb) | terraform-aws-modules/alb/aws | 9.1.0 | | [atlantis](#module\_atlantis) | ../../ | n/a | +| [atlantis\_disabled](#module\_atlantis\_disabled) | ../../ | n/a | | [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws//modules/cluster | 5.6.0 | | [github\_repository\_webhooks](#module\_github\_repository\_webhooks) | ../../modules/github-repository-webhook | n/a | | [secrets\_manager](#module\_secrets\_manager) | terraform-aws-modules/secrets-manager/aws | ~> 1.0 | diff --git a/examples/github-separate/main.tf b/examples/github-separate/main.tf index 83a6db8d..9ab9bfd5 100644 --- a/examples/github-separate/main.tf +++ b/examples/github-separate/main.tf @@ -80,22 +80,6 @@ module "atlantis" { service_subnets = module.vpc.private_subnets vpc_id = module.vpc.vpc_id - # EFS - enable_efs = true - efs = { - mount_targets = { - "eu-west-1a" = { - subnet_id = module.vpc.private_subnets[0] - } - "eu-west-1b" = { - subnet_id = module.vpc.private_subnets[1] - } - "eu-west-1c" = { - subnet_id = module.vpc.private_subnets[2] - } - } - } - tags = local.tags } @@ -108,6 +92,12 @@ module "github_repository_webhooks" { webhook_secret = random_password.webhook_secret.result } +module "atlantis_disabled" { + source = "../../" + + create = false +} + ################################################################################ # Supporting Resources ################################################################################ diff --git a/main.tf b/main.tf index e3709d4b..089dca9f 100644 --- a/main.tf +++ b/main.tf @@ -230,7 +230,7 @@ module "ecs_service" { ignore_task_definition_changes = try(var.service.ignore_task_definition_changes, false) alarms = try(var.service.alarms, {}) capacity_provider_strategy = try(var.service.capacity_provider_strategy, {}) - cluster_arn = var.create_cluster ? module.ecs_cluster.arn : var.cluster_arn + cluster_arn = var.create_cluster && var.create ? module.ecs_cluster.arn : var.cluster_arn deployment_controller = try(var.service.deployment_controller, {}) deployment_maximum_percent = try(var.service.deployment_maximum_percent, 200) deployment_minimum_healthy_percent = try(var.service.deployment_minimum_healthy_percent, 66) @@ -243,7 +243,7 @@ module "ecs_service" { load_balancer = merge( { service = { - target_group_arn = var.create_alb ? module.alb.target_groups["atlantis"].arn : var.alb_target_group_arn + target_group_arn = var.create_alb && var.create ? module.alb.target_groups["atlantis"].arn : var.alb_target_group_arn container_name = "atlantis" container_port = local.atlantis_port } @@ -375,7 +375,7 @@ module "ecs_service" { file_system_id = module.efs.id transit_encryption = "ENABLED" authorization_config = { - access_point_id = module.efs.access_points["atlantis"].id + access_point_id = try(module.efs.access_points["atlantis"].id, null) iam = "ENABLED" } }