hashicorp / terraform-aws-consul-ecs

Consul Service Mesh on AWS ECS (Elastic Container Service)
https://www.consul.io/docs/ecs
Mozilla Public License 2.0
52 stars 30 forks source link

Improve the logic behind the 'defaulted_check_containers' local creation #153

Closed v-rosa closed 1 year ago

v-rosa commented 1 year ago

Changes proposed in this PR:

How I've tested this PR:

How I expect reviewers to test this PR:

Not ideal but this can be tested with this snippet:

locals {
  container_defs_with_depends_on = [{
    name        = "x"
    essential   = true
    healthCheck = null
    },
    {
      name      = "y"
      essential = true
      healthCheck = {
        command = ""
      }
    },
    {
      name      = "z"
      essential = true
    }
  ]

  defaulted_check_containers_before = [for def in local.container_defs_with_depends_on : def.name
  if contains(keys(def), "essential") && contains(keys(def), "healthCheck")]

  defaulted_check_containers_now = [for def in local.container_defs_with_depends_on : def.name
  if contains(keys(def), "essential") && contains(keys(def), "healthCheck") && (try(def.healthCheck, null) != null)]
}

output "defaulted_check_containers_before" {
  value       = local.defaulted_check_containers_before
  description = "should contain 'x' and 'y'"
  depends_on  = []
}

output "defaulted_check_containers_now" {
  value       = local.defaulted_check_containers_now
  description = "should contain only 'y'"
  depends_on  = []
}

tf plan output:

Changes to Outputs:
  + defaulted_check_containers_before = [
      + "x",
      + "y",
    ]
  + defaulted_check_containers_now    = [
      + "y",
    ]

Checklist: