rb16
rb16

Reputation: 129

How to run multiple commands using terraform local-exec

I am trying to run a few az cli commands using terraform using local-exec provisioner but I keep running into an error that says:

Error: Invalid expression

On modules/eventgrid/main.tf line 68: Expected the start of an expression, but
found an invalid expression token.

Here's my code:

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"

    }
  
  }
}

Can anybody please guide me as to what's wrong ?

Upvotes: 7

Views: 12840

Answers (1)

Dan Monego
Dan Monego

Reputation: 10117

With your <<EOT statement, you're inside a string literal already, so you don't need the quotes. Also, <<-EOT (with a dash) is indentation aware, while <<EOT is not.

Finally, as the cause of the issue, you have a space after EOT.

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

Upvotes: 15

Related Questions