是否可以通过environment_name变量打开和关闭access_logs块? [英] Is it possible to turn the access_logs block on and off via the environment_name variable?

查看:46
本文介绍了是否可以通过environment_name变量打开和关闭access_logs块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用中的新条件 > 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.

这是我想制作的块

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?

推荐答案

在当前地形中, if 语句仅是一个值,不能用于该块。

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/providers/aws/r/elb.html#access_logs
  • https://www.terraform.io/docs/providers/aws/r/alb.html#access_logs
  • https://github.com/hashicorp/terraform/pull/11120

这篇关于是否可以通过environment_name变量打开和关闭access_logs块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆