Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LamSut committed Oct 16, 2024
1 parent 803774b commit 68a25e4
Showing 1 changed file with 20 additions and 39 deletions.
59 changes: 20 additions & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
name: Terraform Pipeline
name: Terraform Workflow

on:
push:
branches: [ main ]

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: "us-east-1"
global:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1

jobs:
validate:
setup-terraform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Terraform
- name: Use HashiCorp Terraform action
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.x

- name: Initialize Terraform
run: terraform init

validate:
runs-on: ubuntu-latest
needs: setup-terraform
steps:
- uses: actions/checkout@v3

- name: Validate Terraform configuration
run: terraform validate

Expand All @@ -30,53 +39,25 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install Terraform
uses: hashicorp/setup-terraform@v2

- name: Initialize Terraform
run: terraform init

- name: Create Terraform plan
run: terraform plan -out=planfile

- name: Upload planfile artifact
uses: actions/upload-artifact@v3
with:
name: planfile
path: planfile

apply:
runs-on: ubuntu-latest
needs: plan
steps:
- uses: actions/checkout@v3

- name: Install Terraform
uses: hashicorp/setup-terraform@v2

- name: Download planfile artifact
uses: actions/download-artifact@v3
with:
name: planfile
path: .

- name: Apply Terraform changes (manual approval required)
- name: Apply Terraform plan
run: terraform apply -input=false planfile
env:
TF_IN_AUTOMATION: true # Discourage manual approval in production
if: github.event.inputs.apply # Manual trigger
TF_IN_AUTOMATION: true

destroy:
runs-on: ubuntu-latest
needs: apply
needs: [ apply, ! main ]
steps:
- uses: actions/checkout@v3

- name: Install Terraform
uses: hashicorp/setup-terraform@v2

- name: Destroy Terraform resources (manual approval required)
run: terraform destroy --auto-approve
env:
TF_IN_AUTOMATION: true # Discourage manual approval in production
if: github.event.inputs.destroy # Manual trigger
- name: Destroy Terraform resources
run: terraform destroy --auto-approve

0 comments on commit 68a25e4

Please sign in to comment.