Skip to content

Instantly share code, notes, and snippets.

@MattMencel
Last active February 13, 2019 14:22
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/4bb9870c78b66db2cd36528eb4a4a333 to your computer and use it in GitHub Desktop.
Save MattMencel/4bb9870c78b66db2cd36528eb4a4a333 to your computer and use it in GitHub Desktop.
Terraform Plans with Azure DevOps - Part 2
steps:
- task: JamiePhillips.Terraform.TerraformTool.TerraformTool@0
displayName: 'Use Terraform $(terraform.version)'
inputs:
version: '$(terraform.version)'
- script: |
az login --service-principal -u $(SPN-ID) -p $(SPN-SECRET) --tenant $(TENANT-ID)
ACCESS_KEY=`az storage account keys list -n $(STORAGE_ACCT) -o json | jq -r '.[0].value'`
echo "##vso[task.setvariable variable=ACCESS_KEY]$ACCESS_KEY"
displayName: 'AZ Login and Set ACCESS_KEY'
- script: |
cat << EOT >> terraform.tfvars
access_key = "$(ACCESS_KEY)"
tenant_id = "$(TENANT-ID)"
subscription_id = "$(SUBSCRIPTION-ID)"
client_id = "$(SPN-ID)"
client_secret = "$(SPN-SECRET)"
EOT
workingDirectory: '$(terraform.path)'
displayName: 'Create terraform.tfvars'
- script: |
terraform validate -check-variables=false
workingDirectory: '$(terraform.path)'
displayName: 'Terraform Validate'
- script: |
git config --global --list | grep url. | awk -F '.instead' '{print $1}' | while read line
do
echo $line
git config --global --remove-section $line
done
git config --global url."https://ado:$(System.AccessToken)@foo".insteadOf https://foo
git init
displayName: 'Redirect foo git URLs to use the Access Token So Modules Can Be Pulled In'
- script: |
terraform init -backend-config=resource_group_name=$(RES_GRP) -backend-config=storage_account_name=$(STORAGE_ACCT) -backend-config=container_name=tf-statefiles -backend-config=key=$(state.key) -backend-config=access_key=$(ACCESS_KEY) -no-color -input=false
terraform plan -out=tfplan -no-color -input=false
displayName: 'Terraform Plan'
workingDirectory: '$(terraform.path)'
- script: |
git config --global --remove-section url.https://ado:$(System.AccessToken)@MYDOMAIN
displayName: 'Remove git URL Redirect'
continueOnError: true
condition: always()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment