Azure Devops init going wrong

We have several pipelines in Azure-Devops performing Terraform init-plan-apply. Until now worked fine. But all of a sudden we are getting these errors in the Init phase.

Initializing the backend...
╷
│ Error: Invalid backend configuration argument
│ 
│ The backend configuration argument "arm_subscription_id" given on the command line is not expected for the selected backend type.
╵ Error: Invalid backend configuration argument
│ 
│ The backend configuration argument "arm_tenant_id" .....
│ The backend configuration argument "arm_client_id" .....
│ The backend configuration argument "arm_client_secret" ....

On the hasicorp website I found a remark on this Upgrading to Terraform v0.15 - Terraform by HashiCorp . But thegeneration of the init command is completelly done by DevOps, there is no place where I can change the arm_client_id to client_id (and the others).

Anybody has seen this behaviour and being able to solve it.

1 Like

I had this issue today and resolved it by adding -reconfigure to the init command. This is mentioned in the instructions just below where you read about the changes:

terraform init -reconfigure

You can do that in Azure DevOps by adding -reconfigure to Command Options in the settings panel for the Terraform CLI task if you use the GUI, or commandOptions: '-reconfigure' to the inputs block Terraform CLI task if you use the CLI.

Still getting this back

Starting: Terraform : Init-Reconfigure
==============================================================================
Task         : Terraform
Description  : Execute terraform commands to manage resources on AzureRM, Amazon Web Services(AWS) and Google Cloud Platform(GCP)
Version      : 0.0.142
Author       : Microsoft Corporation
Help         : [Learn more about this task](https://aka.ms/AA5j5pf)
==============================================================================
/usr/local/bin/terraform init -reconfigure -backend-config=storage_account_name=xxx -backend-config=container_name=xxx -backend-config=key=xxx -backend-config=resource_group_name=xxx -backend-config=arm_subscription_id=xxx -backend-config=arm_tenant_id=*** -backend-config=arm_client_id=*** -backend-config=arm_client_secret=***

Initializing the backend...

│ Error: Invalid backend configuration argument
│ 
│ The backend configuration argument "arm_subscription_id" given on the
│ command line is not expected for the selected backend type.

Ok with that output I can see that we are using different marketplace packages for terraform.
I’m using the one published by Charles Zipp, you are using the official Microsoft DevLabs plugin.

The issue you are facing was raised against the Microsoft plugin and it looks like they have not been keeping up with the fact that the arm_ Env var was deprecated some time ago.

So your options:

  1. Set your terraform installer step in your pipeline back to something in the 14.x version when that Env var was still in place, as well as setting/changing the providers version in your main.tf and/or versions.tf to match, or
  2. Wait for the pull request associated with that about issue ticket to be accepted and released.

Given the fact that the PR has been open for more than four months, I’d go with option 1.

In general, I’d recommend hard coding your versions as I mentioned in option 1 to prevent something like this from happening again in the future - that way your can move between versions in a controlled manner and not by surprise.

Whatever I try with versions the ‘thing’ is responds ‘This configuration does not support Terrafrom version 0.15.0…’

So I would like to follow the Zipp-way … I’ve installed the extension but as not being a real DevOps specialist I’m encountering the problem that when trying to add a task it shows the extension, it ‘says’ installed’ but I can’t add it to the Tasks.

Is there any doc on how to use/configure/… the extension ?

Ok, found the problem with the differences between a Extension name and Task name. Could add a Terraform CLI Task. But this happens now…

Starting: terraform init
==============================================================================
Task         : Terraform CLI
Description  : Execute terraform cli commands
Version      : 0.6.21
Author       : Charles Zipp
Help         : 
==============================================================================
/usr/local/bin/terraform version
##[error]Error: There was an error when attempting to execute the process '/usr/local/bin/terraform'. This may indicate the process failed to start. Error: spawn /usr/local/bin/terraform ENOENT
##[error]Error: There was an error when attempting to execute the process '/usr/local/bin/terraform'. This may indicate the process failed to start. Error: spawn /usr/local/bin/terraform ENOENT

Finishing: terraform init

The backend type is set to azurerm, the Azure RM Backend Config is passed by variables.
When I do look into the YAMPL script there are ‘error’ about these variables, but in our regular scripts these error are found too

#Your build pipeline references an undefined variable named ‘main_directory’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘tfstate_subscription’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘tfstate_subscription’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘tfstate_storageaccount’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘tfstate_container’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘tfstate_directory’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

steps:
- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-cli.TerraformCLI@0
  displayName: 'terraform init'
  inputs:
    command: init
    workingDirectory: '$(main_directory)'
    backendType: azurerm
    backendServiceArm: '$(tfstate_subscription)'
    backendAzureRmResourceGroupName: '$(tfstate_subscription)'
    backendAzureRmStorageAccountName: '$(tfstate_storageaccount)'
    backendAzureRmContainerName: '$(tfstate_container)'
    backendAzureRmKey: '$(tfstate_directory)/terraform.tfstate'