如何使用 terraform local-exec 运行 多个命令
How to run multiple commands using terraform local-exec
我正在尝试 运行 使用 terraform 使用 local-exec provisioner 运行 一些 az cli 命令,但我一直 运行 遇到一个错误,上面写着:
Error: Invalid expression
On modules/eventgrid/main.tf line 68: Expected the start of an expression, but
found an invalid expression token.
这是我的代码:
resource "null_resource" "eg-role-assignment" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOT
"az account set --subscription foo"
"az eventgrid topic update --resource-group $RESOURCE_GROUP --name $EVENTGRID_NAME --identity systemassigned"
EOT
environment = {
RESOURCE_GROUP = "RG_${var.platform_tag}_${var.product_code}_PUBLISH_${var.environment}_${var.location_code_primary}"
EVENTGRID_NAME = "EG-${var.platform_tag}-${var.product_code}-${var.environment}-${var.location_code_primary}-domain"
}
}
}
任何人都可以指导我哪里出了问题吗?
使用 <<EOT
语句,您已经在字符串文字中,因此不需要引号。此外,<<-EOT
(带破折号)是缩进感知的,而 <<EOT
不是。
最后,作为问题的原因,您在 EOT
之后有一个 space。
command = <<-EOT
az account set --subscription foo
az eventgrid topic update --resource-group $RESOURCE_GROUP --name $EVENTGRID_NAME --identity systemassigned
EOT
我正在尝试 运行 使用 terraform 使用 local-exec provisioner 运行 一些 az cli 命令,但我一直 运行 遇到一个错误,上面写着:
Error: Invalid expression
On modules/eventgrid/main.tf line 68: Expected the start of an expression, but
found an invalid expression token.
这是我的代码:
resource "null_resource" "eg-role-assignment" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOT
"az account set --subscription foo"
"az eventgrid topic update --resource-group $RESOURCE_GROUP --name $EVENTGRID_NAME --identity systemassigned"
EOT
environment = {
RESOURCE_GROUP = "RG_${var.platform_tag}_${var.product_code}_PUBLISH_${var.environment}_${var.location_code_primary}"
EVENTGRID_NAME = "EG-${var.platform_tag}-${var.product_code}-${var.environment}-${var.location_code_primary}-domain"
}
}
}
任何人都可以指导我哪里出了问题吗?
使用 <<EOT
语句,您已经在字符串文字中,因此不需要引号。此外,<<-EOT
(带破折号)是缩进感知的,而 <<EOT
不是。
最后,作为问题的原因,您在 EOT
之后有一个 space。
command = <<-EOT
az account set --subscription foo
az eventgrid topic update --resource-group $RESOURCE_GROUP --name $EVENTGRID_NAME --identity systemassigned
EOT