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 ?

1 Answer 1

15

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
Sign up to request clarification or add additional context in comments.

3 Comments

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 ?
Ah! You had an extra space on your heredoc anchor - <<-EOF instead of <<-EOF. That was the root issue.
The answer's been updated to remove the extra whitespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.