Closed chris-b-chalmers closed 1 month ago
Currently its not possible. we will evaluate this suggestion.
Why is this still not possible. It dopes not make any sense. You configure the backend in the provider section of your terraform script.
I find this issue to be ridiculous as well. I did manage to get it to working using a PowerShell task that called terraform init -backend=false
directly, but it would be much nicer to be able to do so using the proper extension.
This is an issue in TerraformTaskV2@2 as well. Should that be a separate issue?
+1 for this
+1 for this, I have my remote states in different storage accounts and I'd like to init without the need to target any environment for the purpose of just wanting to run validate afterwards. I'll have to do it in powershell for now but this would be a nice addition just having a flag to say if -backend=false
I found a better work around for me. I populated the required fields with N/A and put -backend=false
as a command option. This allows me to init locally for the build step then I can init remote for my specific environment branches.
- task: TerraformTaskV3@3
displayName: 'Terraform init test'
inputs:
provider: 'azurerm'
command: 'init'
commandOptions: '-input=false -backend=false'
workingDirectory: '${{parameters.tf_path}}'
backendServiceArm: '${{parameters.tf_azurerm}}'
backendAzureRmResourceGroupName: 'N/A'
backendAzureRmStorageAccountName: 'N/A'
backendAzureRmContainerName: 'N/A'
backendAzureRmKey: 'N/A'
In my dev, qa and production stages I just need to remove the .terraform folder to make sure I don't get the error "migrate state needed"
rm -rf directoryname $(Pipeline.Workspace)/terraform/.terraform
+1 for this. Believe it's an issue as of v4 still.
I'm not sure of the exact use case here? The purpose of the Task is to simplify using a Service Connection with Terraform. It is designed for running Terraform with connections to Cloud providers.
If you are just running a local fmt / validate you don't need the task or a Service Connection. It actually makes it more complicated than it needs to be. I appreciate the Task could be updated to handle this edge case more gracefully, but in the meantime you can just use the standard CLI tooling.
E.g.
jobs:
- job: validate
displayName: Validate Terraform
pool:
vmImage: ubuntu-latest
steps:
- task: TerraformInstaller@0
displayName: Install Terraform
inputs:
terraformVersion: 'latest'
- pwsh: terraform fmt -check
displayName: Terraform Format Check
- pwsh: terraform init -backend=false
displayName: Terraform Init
- pwsh: terraform validate
displayName: Terraform Validate
Example taken from here.
closing this; alternative way provided
I am looking to have a pipeline which only runs a Terraform install, Terraform init then Terraform validate. This works normally when I specify my backendServiceArm, backendAzureRmResourceGroupName, backendAzureRmStorageAccountName, backendAzureRmContainerName and backendAzureRmKey inputs.
I'm aiming to remove the backend configuration so that I dont need to grant this pipeline access into Azure, and any validation can be done only within Azure DevOps.
I have tried combinations of the following but it always errors with "##[error]Error: Input required: backendServiceArm"
Is there a way to accomplish this using the extension?