Skip to content

chore: Remove unnecessary backend destruction step in deploy_aws_vpc.yml #117

chore: Remove unnecessary backend destruction step in deploy_aws_vpc.yml

chore: Remove unnecessary backend destruction step in deploy_aws_vpc.yml #117

name: Validate AWS Opentofu templates
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
jobs:
deploy:
name: Deploy Infrastructure
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_INFRA_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_INFRA_KEY }}
steps:
- uses: actions/checkout@v3
- uses: opentofu/[email protected]
name: Setup OpenTofu
- name: Setup SSH Key using webfactory/ssh-agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: OpenTofu Setup Backend
run: |
cd ./IaC/aws/backend/
tofu init
tofu validate
tofu plan -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
tofu apply -auto-approve -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
- name: OpenTofu Setup and Validate
run: |
cd ./IaC/aws/tofu/
tofu init
tofu validate
tofu plan -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
- name: Deploy VPC
if: github.ref == 'refs/heads/main'
run: |
cd ./IaC/aws/tofu/
tofu apply -auto-approve -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
- name: Destroy VPC
if: always()
run: |
cd ./IaC/aws/tofu/
tofu destroy -auto-approve -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
- name: Destroy Backend
if: always()
run: |
cd ./IaC/aws/backend/
tofu destroy -auto-approve -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"