Is it possible to turn the access_logs block on and off via the environment_name variable?

前端 未结 5 525
一个人的身影
一个人的身影 2020-12-29 19:43

I\'m looking at using the new conditionals in Terraform v0.11 to basically turn a config block on or off depending on the evnironment.

Here\'s the b

5条回答
  •  清酒与你
    2020-12-29 20:15

    Expanding on Juho Rutila’s answer too; I like to use the range function for this use case:

    dynamic "access_logs" {
      for_each = range(var.environment_name == "production" ? 1 : 0)
    
      contents {
        bucket  = "my-bucket"
        prefix  = "${var.environment_name}-alb"
      }
    }
    

    range(n) produces a n-element list.

提交回复
热议问题