Skip to content

Terraform Plan Destroy #1

Terraform Plan Destroy

Terraform Plan Destroy #1

name: Terraform Plan Destroy
on:
workflow_dispatch:
jobs:
plan:
environment: test
name: "Run Terraform Plan"
runs-on: ubuntu-20.04
env:
tf-version: 1.3.9
defaults:
run:
working-directory: .
steps:
- name: 'Checkout'
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.tf-version }}
terraform_wrapper: true
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
- name: Terraform Init
id: init
run: terraform init -no-color
- name: Create Artifact Folder
shell: bash
run: |
sudo mkdir -p -m777 ${{ github.workspace }}/tfplanoutput
- name: Terraform Plan
id: plan
run: |
terraform plan -destroy -no-color -var-file=test-env.tfvars -out=${{ github.workspace }}/tfplanoutput/tf.plan
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: artifact
path: ${{ github.workspace }}/tfplanoutput/
if-no-files-found: error
apply:
name: "Run Terraform Apply"
needs: plan
runs-on: ubuntu-20.04
env:
tf-version: 1.3.9
environment: test
steps:
- name: 'Checkout'
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.tf-version }}
terraform_wrapper: true
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
- name: Terraform Init
id: init
run: terraform init -no-color
- name: Download Build Artifact
uses: actions/download-artifact@v3
with:
name: artifact
path: ${{ github.workspace }}/tfplanoutput
- name: Terraform Apply
id: apply
run: |
terraform apply -no-color -input=false ${{ github.workspace }}/tfplanoutput/tf.plan
- name: Terraform Output
id: output
run: |
terraform output