Created
March 28, 2021 02:44
-
-
Save KyMidd/ae6890eaa94e10ebb1bbd0374abd5f13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - 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