Update terraform-deploy.yml #3
This file contains 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 Deployment | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.5.7 | |
- name: Configure AWS credentials | |
run: | | |
mkdir -p ~/.aws | |
echo "[default]" > ~/.aws/credentials | |
echo "aws_access_key_id=${{ secrets.AWS_ACCESS_KEY_ID }}" >> ~/.aws/credentials | |
echo "aws_secret_access_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> ~/.aws/credentials | |
- name: Initialize Terraform | |
run: terraform init | |
- name: Format Terraform files | |
run: terraform fmt | |
- name: Validate Terraform configuration | |
run: terraform validate | |
- name: Apply Terraform changes | |
run: terraform plan | |
- name: Run terraform plan | |
run: terraform apply | |
destroy: | |
needs: deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Manual Step - Destroy Infrastructure | |
run: terraform destroy |