'Specify local tf state file to azurerm provider in pipeline

I have been working on deploying terraform package using azure devops pipeline.

We have our tf state file locally, and no plans to move to azure storage account. Could you please help how can we define the attribute values in terraform init step in pipeline.

- task: TerraformTaskV2@2
    displayName: Terraform init
    inputs:
      provider: 'azurerm'
      command: 'init'
      workingDirectory: 'some directory'
      backendServiceArm: 'some service conn'
      **backendAzureRmContainerName: ??
      backendAzureRmResourceGroupName: ??
      backendAzureRmStorageAccountName: ??
      backendAzureRmKey: ** 

What should be the values for Resource group, storage account name, container name. If I don't specify these values, pipeline is failing with below error

##[error]Error: Input required: backendAzureRmStorageAccountName

Any help on this is much appreciated. Thanks in advance.



Solution 1:[1]

I'm unsure if you can use the TerraformTaskV2 without utilizing a cloud provider's backend. In the README for said task it doesn't show options for using a local backend, only the following for terraform init:

  • ... AzureRM backend configuration
  • ... Amazon Web Services(AWS) backend configuration
  • ... Google Cloud Platform(GCP) backend configuration

I haven't had experience with this yet, but you could look at the extension Azure Pipelines Terraform Tasks, which does explicitly support a local backend:

The Terraform CLI task supports the following terraform backends

  • local
  • ...

Just a note on working in teams:
if you're working in a team deploying infrastructure, using a local backend can lead to potential undefined state and/or undesirable outcomes. The benefits of choosing a good backend can offer "...support locking the state while operations are being performed, which helps prevent conflicts and inconsistencies." - docs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1