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

前端 未结 5 527
一个人的身影
一个人的身影 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条回答
  •  猫巷女王i
    2020-12-29 20:09

    Expanding on Juho Rutila's answer as it's too much to fit in a comment.

    This is possible using dynamic blocks from v0.12, but I found the properties had to be included in a nested content block. The for_each statement is also a bit tricky, so I found it sensible to extract that into a local to make the important stuff more readable:

    locals {
      isProd = var.environment_name == "production" ? [1] : []
    
      // Not necessary, but just illustrating that the reverse is possible
      isNotProd = var.environment_name == "production" ? [] : [1]
    }
    
    dynamic "access_logs" {
      for_each = local.isProd
      content {
        bucket  = "my-bucket"
        prefix  = "${var.environment_name}-alb"
      }
    }
    

    You can read more about dynamic blocks here: https://www.terraform.io/docs/configuration/expressions.html#dynamic-blocks

提交回复
热议问题