是否可以通过 environment_name 变量打开和关闭 access_logs 块? [英] Is it possible to turn the access_logs block on and off via the environment_name variable?
问题描述
我正在考虑在 新条件>Terraform v0.11 基本上根据环境打开或关闭配置块.
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 block that I'd like to make into a conditional, if, for example I have a variable to turn on for production.
access_logs {
bucket = "my-bucket"
prefix = "${var.environment_name}-alb"
}
我认为我有条件检查环境的逻辑,但我不知道如何将上述配置粘贴到逻辑中.
I think I have the logic for checking the environment conditional, but I don't know how to stick the above configuration into the logic.
"${var.environment_name == "production" ? 1 : 0 }"
是否可以通过 environment_name
变量打开和关闭 access_logs
块?如果这不可能,是否有解决方法?
Is it possible to turn the access_logs
block on and off via the environment_name
variable? If this is not possible, is there a workaround?
推荐答案
在当前的terraform中,if
语句只是一个值,不能用于block.
In the current terraform, the if
statement is only a value and can not be used for the block.
在这种情况下有一个解决方法.您可以将 access_log
块的 enabled
属性设置为 false
.请注意,这不是通用解决方案,只能与 access_log
块一起使用.
There is a workaround in this case. You can set the enabled
attribute of the access_log
block to false
. Note that this is not a general solution but can only be used with the access_log
block.
access_logs {
bucket = "my-bucket"
prefix = "${var.environment_name}-alb"
enabled = "${var.environment_name == "production" ? true : false }"
}
另见:
- https://www.terraform.io/docs/提供者/aws/r/elb.html#access_logs
- https://www.terraform.io/docs/提供者/aws/r/alb.html#access_logs
- https://github.com/hashicorp/terraform/pull/11120
这篇关于是否可以通过 environment_name 变量打开和关闭 access_logs 块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!