Skip to content

Instantly share code, notes, and snippets.

@MattMencel
Last active September 27, 2019 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattMencel/6ae76651718b09f21771d581e5830d73 to your computer and use it in GitHub Desktop.
Save MattMencel/6ae76651718b09f21771d581e5830d73 to your computer and use it in GitHub Desktop.
Azure CLI Tasks to Authenticate with an SPN
- task: AzureCLI@1
displayName: 'Setup Authentication'
inputs:
azureSubscription: '$(SUBSCRIPTION_NAME)'
addSpnToEnvironment: true
scriptLocation: inlineScript
failOnStandardError: 'true'
inlineScript: |
echo "##vso[task.setvariable variable=ARM_SUBSCRIPTION_ID]$(az account show --query="id" -o tsv)"
echo "##vso[task.setvariable variable=ARM_CLIENT_ID]${servicePrincipalId}"
echo "##vso[task.setvariable variable=ARM_CLIENT_SECRET]${servicePrincipalKey}"
echo "##vso[task.setvariable variable=ARM_TENANT_ID]$(az account show --query="tenantId" -o tsv)"
echo "##vso[task.setvariable variable=ARM_ACCESS_KEY]$(az storage account keys list -n ${STORAGE_ACCOUNT} --query="[0].value" -o tsv
- script: |
export TF_IN_AUTOMATION=true
export TF_VAR_subscription_id="$(ARM_SUBSCRIPTION_ID)"
export TF_VAR_client_id="$(ARM_CLIENT_ID)"
export TF_VAR_client_secret="$(ARM_CLIENT_SECRET)"
export TF_VAR_tenant_id="$(ARM_TENANT_ID)"
export TF_VAR_vm_username="$(vm_username)"
export TF_VAR_vm_password="$(vm_password)"
terraform init -no-color -input=false
terraform plan -out=tfplan -no-color -input=false
displayName: 'Terraform Plan'
workingDirectory: '$(TFPATH)'
enabled: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment