Terraform Destroy #4
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
| name: 'Terraform Destroy' | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| module: | |
| type: choice | |
| description: "Select which module to destroy" | |
| options: | |
| - module-1 | |
| - module-2 | |
| required: true | |
| permissions: write-all | |
| jobs: | |
| terraform: | |
| name: 'Terraform' | |
| runs-on: ubuntu-latest | |
| environment: production | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: "us-east-1" | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| # Checkout the repository to the GitHub Actions runner | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Set Account ID | |
| id: account | |
| run: | | |
| echo "::set-output name=ACCOUNT_ID::$(aws sts get-caller-identity --query Account --output text)" | |
| # Copy and delete terraform.tfstate files from s3 bucket | |
| - name: Retrieve tfstate | |
| run: | | |
| cd modules/${{ github.event.inputs.module }} | |
| aws s3 cp s3://do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }}/terraform.tfstate ./terraform.tfstate | |
| # Initialize a new Terraform working directory | |
| - name: Terraform Init | |
| run: | | |
| cd modules/${{ github.event.inputs.module }} | |
| terraform init | |
| - name: Terraform Destroy | |
| run: | | |
| cd modules/${{ github.event.inputs.module }} | |
| terraform destroy -auto-approve -input=false | |
| continue-on-error: false |