terraform是否提供了覆盖变量值的功能?假设我声明了下面给出的两个变量。
variable "foo" {}
variable "bar" { default = "false"}foo是强制性的,bar是用默认值false分配的。在terraform中是否有任何resoruce可以重新分配或重写bar值?我从resource的角度来问这个问题。我知道我可以用terraform-modules来做这件事。
我尝试过使用null_resource,但没有得到预期的结果。它仍然返回默认值。
resource "null_resource" "this" {
provisioner "local-exec" {
command = "echo ${var.env} > ${var.newvar}"
}
}另外,我还想在curl命令属性中运行。我需要用一个‘翻译’吗?如果是的话,那它的金库是什么呢?
interpreter = ["shell","?"]在local-exec提供程序中执行curl命令应该传递什么值。
bash脚本
function check_efs() {
curl -ls https://elasticfilesystem.us-east-1.amazonsaws.com
if [ $? -eq 0 ]; then
output=1
else:
output=0
}
function produce_output() {
value=$(output)
jq -n \
--arg is_efs_exist "$value" \
'{"is_efs_exist":$is_efs_exist}'
}
check_efs
produce_output发布于 2018-10-12 15:41:48
回答第一个关于越野的问题..。
有几种方法可以解决这个问题。我不知道你确切的用例,所以你的里程可能会有所不同。
bar将export TF_VAR_bar=newvalue变量设置为一个新值,然后在该会话中运行terraform。或者将它们合并到同一行:TF_VAR_bar=newvalue terraform apply
参考文献:https://www.terraform.io/docs/configuration/environment-variables.htmloverride.tf可以包含variable "bar" { default = "newvalue"}或任何其他TF代码。最后上膛了。
参考文献:https://www.terraform.io/docs/configuration/override.htmlbar值。如果您一直重复使用相同的代码,并且希望提供具有不同参数的资源集的不同实例,这尤其有用。
参考文献:https://www.terraform.io/docs/configuration/modules.html哈哈!
https://stackoverflow.com/questions/52774464
复制相似问题