Azure DevOps Terraform Init - Remote State - Failed to get existing workspaces: containers.Client#ListBlobs: Failure sending request: StatusCode=0

Viewed 12236

Experiencing terraform for the very time, I'm following the document from this link to put in my terraform files in a release pipeline that I have with Azure DevOps. Everything runs perfectly fine until the step where it initializes the terraform. It fails with the following error message:

enter image description here

The storage account itself is provisioned and the key of that also is persisted successfully in the environment variables as per the document.

The YAML I have for terraform init in Azure DevOps Release pipeline is: enter image description here

And the terraform script for the backend service is: enter image description here

The variables are stored as environment variables inside the release pipeline and there is a replace token task that replaces __ with string empty: enter image description here

Her is the step in the pipeline that create the resource group and storage account: enter image description here

And finally, the PS scripts that store the storage key in the ENV vars: enter image description here

Also, I can't understand why the get http from the error message has env appended to the terraform.tformstate.

I'm running out of ideas why it fails with that exception and what is expecting actually.

I've been Googling around but have been failing so far to resolve the issue. Appreciate your help/thoughts on this.

2 Answers

Looks like you misspelled storageaccount for your variable. So the value is not substituted. You have sotrageaccount. The t and o are swapped.

While Christian Pearce did answer the immediate question, there is underlying problem for this message.
There is something wrong with your Storage Account settings

The issue I had was that I placed path information into the Container name

- task: TerraformTaskV3@3
  displayName: Terraform Init
  inputs:
    provider: azurerm
    command: init
    backendServiceArm: [service connection]
    backendAzureRmResourceGroupName: [resource group]
    backendAzureRmStorageAccountName: [storage account name]
    backendAzureRmContainerName: [container]/subfolder <-- This is bad and belongs in the Key field
    backendAzureRmKey: ${{ parameters.name }}/${{ parameters.environment }}.tfstate
    workingDirectory: $(Pipeline.Workspace)/Infrastructure
Related