terraform - 如何使用 terraform local-exec 运行多个命令

标签 terraform azure-cli terraform-provider-azure

我正在尝试使用 terraform 使用 local-exec 配置器运行一些 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 后面有一个空格.

command = <<-EOT
          az account set --subscription foo
          az eventgrid topic update --resource-group $RESOURCE_GROUP --name $EVENTGRID_NAME --identity systemassigned
EOT

关于terraform - 如何使用 terraform local-exec 运行多个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68957371/

相关文章:

azure - 无需手动交互即可登录 Az

terraform - 如何声明使用不同协议(protocol)端口的 azurerm_container_group 资源?

amazon-web-services - 我无法通过 SSH 连接到使用 Terraform 创建的 EC2 实例

amazon-web-services - 如何解决错误加载状态: AccessDenied: Access Denied status code: 403 when trying to use s3 for terraform backend?

azure - Terraform Azure AKS - 如何安装 azure-keyvault-secrets-provider 附加组件

azure - 从模块中提取资源详细信息以在另一个模块中使用

bash - 使用 Terraform 运行 Azure AZ 登录命令

aws-lambda - Terraform 在 zip 准备好之前创建 lambda

azure - 如何使用 az CLI 获取 Azure Log Analytics 的工作区 ID?

azure - az ml dataset create 上的“create”拼写错误或未被系统识别