7

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 ?

rb16
  • 129
  • 4
  • 11

1 Answers1

14

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
Dan Monego
  • 9,637
  • 6
  • 37
  • 72
  • Hello @Dan Monego! Thanks for that suggestion. However, I'm still running into the same issue. Is there anything else I might be missing out on ? – rb16 Aug 27 '21 at 18:25
  • Ah! You had an extra space on your heredoc anchor - `<<-EOF ` instead of `<<-EOF`. That was the root issue. – Dan Monego Aug 27 '21 at 18:28
  • The answer's been updated to remove the extra whitespace. – Dan Monego Aug 27 '21 at 18:38