Grappachu
Grappachu

Reputation: 1344

How to remove Terraform double quotes?

I created a YML pipeline using terraform . It uses a script task and returns in output the web app name

steps:
- script: | 
    [......] 
    terraform apply -input=false -auto-approve
    
    # Get the App Service name for the dev environment.
    WebAppNameDev=$(terraform output appservice_name_dev)
    
    # Write the WebAppNameDev variable to the pipeline.
    echo "##vso[task.setvariable variable=WebAppNameDev;isOutput=true]$WebAppNameDev"
  name: 'RunTerraform'

The task works fine but when i deploy the webapp it crashes because seems variable $WebAppNameDev has double quotes.

      - task: AzureWebApp@1
        displayName: 'Azure App Service Deploy: website'
        inputs:
          azureSubscription: 'MySubscription'
          appName: $(WebAppNameDev)
          package: '$(Pipeline.Workspace)/drop/*.zip'

The error looks like:

 Got service connection details for Azure App Service:'"spikeapp-dev-6128"'
 ##[error]Error: Resource '"spikeapp-dev-6128"' doesn't exist. Resource should exist before deployment.

How can i remove double quotes or fix the terraform output?

Upvotes: 12

Views: 7167

Answers (1)

Grappachu
Grappachu

Reputation: 1344

I solved by adding -raw parameter to terraform output.

WebAppNameDev=$(terraform output -raw appservice_name_dev)

ref. https://www.terraform.io/docs/cli/commands/output.html

Upvotes: 35

Related Questions