Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created March 28, 2021 02:44
Show Gist options
  • Select an option

  • Save KyMidd/ae6890eaa94e10ebb1bbd0374abd5f13 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/ae6890eaa94e10ebb1bbd0374abd5f13 to your computer and use it in GitHub Desktop.
- task: Bash@3
name: AutoApprovalTest
displayName: Auto-Approval Test
inputs:
targetType: 'inline'
workingDirectory: $(System.DefaultWorkingDirectory)/$(tf_directory)
failOnStderr: true
script: |
# If no changes, no-op and don't continue
if terraform show plan.out | grep -q " 0 to add, 0 to change, 0 to destroy"; then
echo "##[section]No changes, terraform apply will not run";
# Check if resources destroyed. If no, don't require approval
elif terraform show plan.out | grep -q "to change, 0 to destroy"; then
echo "##[section]Approval not required";
echo "##[section]Automatic terraform apply triggered";
echo "##vso[task.setvariable variable=approvalRequired;isOutput=true]false"
# Check if resources destroyed. If yes, require approvals
else
echo "##[section]Terraform apply requires manual approval";
echo "##vso[task.setvariable variable=approvalRequired;isOutput=true]true"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment