jason-johnson / azure-pipelines-tasks-terraform

Azure Pipelines extension for Terraform
MIT License
122 stars 51 forks source link

How to use service connections in tasks? #402

Closed slydewd closed 6 months ago

slydewd commented 6 months ago

I am currently trying to setup a Terraform pipeline in ADO pipelines using this task, but I don't know any of the inputs. Is there any docs that shows all the different inputs I can use for the tasks?

I am currently using TerraformTaskV4@4 at my org, but I see it has been depreciated and I want to move the tasks to TerraformCLI@V2. I am using TerraformInstaller@2 to install Terraform.

TerraformTask

    - task: TerraformTaskV4@4
      displayName: 'Init'
      inputs:
        provider: 'azurerm'
        command: 'init'
        workingDirectory: '$(workingDir)'
        backendServiceArm: 'serviceConnection'
        backendAzureRmResourceGroupName: 'resourceGroup'
        backendAzureRmStorageAccountName: 'storageAccount'
        backendAzureRmContainerName: 'tfstate'
        backendAzureRmKey: 'terraform.tfstate'

TerraformCLI

- task: TerraformCLI@2
      displayName: 'Init'
      inputs:
        command: 'init'
        allowTelemetryCollection: false
        workingDirectory: '$(workingDir)'

As you can see, I am missing the input for specifying the service connection to use, and the terraform backend config.

Terraform Backend Config

backend "azurerm" {
    # terraform state file name / not sure if needed
    key = "terraform.tfstate"
    # enables federated credentials (OpenID Connect)
    use_oidc = true
    # aad authentication
    use_azuread_auth = true
  }
}
slydewd commented 6 months ago

Looks like I found it 🫠 https://github.com/jason-johnson/azure-pipelines-tasks-terraform/blob/main/overview.md#azure-service-connection--service-principal-integration

I'll close the issue