I'm trying to run Terraform from a PowerShell step in a YAML-configured Azure DevOps Pipeline, but I can't get it to accept my incantation: instead of initializing the state, it prints the usage instructions and exits.
I've tried a number of combinations of with/without quotes for the -backend-config
parameter, but nothing seems to work.
If I cut-and-paste the script into a ps1
file locally and run it, everything works as expected.
What is wrong with my incantation of ./terraform.exe init
here?
Here's the pipeline configuration, in its entirety:
pool:
vmImage: 'win1803'
steps:
- powershell: |
# Download the Terraform executable into the current directory
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = 'https://releases.hashicorp.com/terraform/0.11.8/terraform_0.11.8_windows_amd64.zip'
$output = "$PSScriptRoot\terraform.zip"
Write-Host "Downloading from $url to $output"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
Expand-Archive $output -DestinationPath . -Force
Get-ChildItem
displayName: 'Download Terraform executable'
- powershell: |
# Create a config file with secrets, and initialize Terraform
"storage_account_name = `"$env:TerraformStateAccountName`"" | Out-File "./terraform-state.secrets.tfvars" -Append
"access_key = `"$env:TerraformStateAccountKey`"" | Out-File "./terraform-state.secrets.tfvars" -Append
"container_name = `"$env:TerraformStateContainer`"" | Out-File "./terraform-state.secrets.tfvars" -Append
./terraform.exe init -backend-config=./terraform-state.secrets.tfvars -input=false
env:
TerraformStateAccountName: $(Terraform.State.StorageAccountName)
TerraformStateAccountKey: $(Terraform.State.StorageAccountKey)
TerraformStateContainer: $(Terraform.State.ContainerName)
displayName: 'Initialize Terraform'
./terraform.exe init -foo
locally, except locally I get a final line sayingflag provided but not defined: -foo
while on the build server I get no message at all. – Tomas Aschan./terraform.exe init -foo
is not included on the build server. (If you want to be rude, at least don't put words in my mouth in order to have something to be rude about.) – Tomas Aschan