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.

Revisions

  1. KyMidd created this gist Mar 28, 2021.
    23 changes: 23 additions & 0 deletions tf_approval_bash_in_task.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    - 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