1
votes

I am tying to run terraform on my azure Devops pipeline. I am using the terraform extension version 0.1.8 from the marketplace by MicrosoftDevLabs My task looks as below :

task: TerraformTaskV1@0
displayName: 'Terraform - Init'
inputs:
provider: 'azurerm'
command: 'init'
commandOptions: '-input=false'
backendServiceArm: 'service-connection'
backendAzureRmResourceGroupName: 'Project-RG'
backendAzureRmStorageAccountName: 'projectsa'
backendAzureRmContainerName: 'tfstate'
backendAzureRmKey: 'terraform.tfstate'
workingDirectory: terraform

The command it tries to execute is

`/opt/hostedtoolcache/terraform/0.13.5/x64/terraform init -backend-config=storage_account_name=projectsa -backend-config=container_name=tfstate -backend-config=key=terraform.tfstate -backend-config=resource_group_name=Project-RG -backend-config=arm_subscription_id=xxxx-xxxx-xxxx -backend-config=arm_tenant_id=*** -backend-config=arm_client_id=*** -backend-config=arm_client_secret=***’

And the error message is:

Initializing the backend...  
Error: Invalid backend configuration argument
The backend configuration argument "storage_account_name" given on the command line is not expected for the selected backend type.   
Error: Invalid backend configuration argument  
The backend configuration argument "container_name" given on the command line is not expected for the selected backend type.   
Error: Invalid backend configuration argument  
The backend configuration argument "key" given on the command line is not expected for the selected backend type.
2
Can you paste the error message?Grzegorz Oledzki
Hello, the error is as such : Initializing the backend... Error: Invalid backend configuration argument The backend configuration argument "storage_account_name" given on the command line is not expected for the selected backend type. Error: Invalid backend configuration argument The backend configuration argument "container_name" given on the command line is not expected for the selected backend type. Error: Invalid backend configuration argument The backend configuration argument "key" given on the command line is not expected for the selected backend type. Cloudhubzawsaz

2 Answers

3
votes

Fixed it. The solution is slightly embarrassing. The.tf files backend was mentioned as local. Which now makes sense as local backend does not support these parameters. Changing the backend to azure fixed it. Make sure you have the correct backend defined as the error does say the parameters for the backend are not supported.

1
votes

I ran this

- task: TerraformInstaller@0
  inputs:
    terraformVersion: '0.13.5'
- task: TerraformTaskV1@0
  inputs:
    provider: 'azurerm'
    command: 'init'
    workingDirectory: '$(System.DefaultWorkingDirectory)/stackoverflow/74-terraform'
    backendServiceArm: 'rg-the-code-manual'
    backendAzureRmResourceGroupName: 'TheCodeManual'
    backendAzureRmStorageAccountName: 'thecodemanual'
    backendAzureRmContainerName: 'infra'
    backendAzureRmKey: 'tfstate-so-74'
    commandOptions: '-input=false'

and got it working

2020-12-04T10:06:25.4318809Z [command]/opt/hostedtoolcache/terraform/0.13.5/x64/terraform init -backend-config=storage_account_name=thecodemanual -backend-config=container_name=infra -backend-config=key=tfstate-so-74 -backend-config=resource_group_name=TheCodeManual -backend-config=arm_subscription_id=<subscriptionId> -backend-config=arm_tenant_id=*** -backend-config=arm_client_id=*** -backend-config=arm_client_secret=***
2020-12-04T10:06:25.4670082Z 
2020-12-04T10:06:25.4675423Z [0m[1mInitializing the backend...[0m
2020-12-04T10:06:25.4738557Z [0m[32m
2020-12-04T10:06:25.4740133Z Successfully configured the backend "azurerm"! Terraform will automatically
2020-12-04T10:06:25.4742265Z use this backend unless the backend configuration changes.[0m
2020-12-04T10:06:25.9242628Z [33m
2020-12-04T10:06:25.9244849Z [1m[33mWarning: [0m[0m[1m"arm_client_id": [DEPRECATED] `arm_client_id` has been replaced by `client_id`[0m
2020-12-04T10:06:25.9246980Z 
2020-12-04T10:06:25.9248608Z [0m[0m[0m
2020-12-04T10:06:25.9249659Z [33m
2020-12-04T10:06:25.9251909Z [1m[33mWarning: [0m[0m[1m"arm_client_secret": [DEPRECATED] `arm_client_secret` has been replaced by `client_secret`[0m
2020-12-04T10:06:25.9252897Z 
2020-12-04T10:06:25.9254321Z [0m[0m[0m
2020-12-04T10:06:25.9255028Z [33m
2020-12-04T10:06:25.9256913Z [1m[33mWarning: [0m[0m[1m"arm_tenant_id": [DEPRECATED] `arm_tenant_id` has been replaced by `tenant_id`[0m
2020-12-04T10:06:25.9261480Z 
2020-12-04T10:06:25.9262574Z [0m[0m[0m
2020-12-04T10:06:25.9263605Z [33m
2020-12-04T10:06:25.9264816Z [1m[33mWarning: [0m[0m[1m"arm_subscription_id": [DEPRECATED] `arm_subscription_id` has been replaced by `subscription_id`[0m
2020-12-04T10:06:25.9265629Z 

With info about deprecation of settings, but this at the moment doesn't lead to a fail. For this there is already issue and PR on github.

Did you run TerraformInstaller before TerraformTaskV1?