Skip to content

Instantly share code, notes, and snippets.

@geekzter
Last active April 6, 2021 18:12
Show Gist options
  • Save geekzter/8b01c8f76c47f7d14e63258dd3d1169e to your computer and use it in GitHub Desktop.
Save geekzter/8b01c8f76c47f7d14e63258dd3d1169e to your computer and use it in GitHub Desktop.
Terraform authentication inherits Azure Pipeline Service Connection credentials
- task: AzureCLI@2
displayName: 'Terraform init'
inputs:
azureSubscription: '$(subscriptionConnection)'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
# Propagate pipeline Service Principal as Terraform variables
$env:ARM_CLIENT_ID ??= $env:servicePrincipalId
$env:ARM_CLIENT_SECRET ??= $env:servicePrincipalKey
$env:ARM_TENANT_ID ??= $env:tenantId
# Propagate from Azure CLI context
$env:ARM_TENANT_ID ??= $(az account show --query tenantId -o tsv)
$env:ARM_SUBSCRIPTION_ID ??= $(az account show --query id -o tsv)
# Put Terraform commands after this line
addSpnToEnvironment: true
useGlobalConfig: true
failOnStandardError: true
powerShellIgnoreLASTEXITCODE: false
workingDirectory: '$(terraformDirectory)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment