-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (50 loc) · 1.94 KB
/
deploy_aws_vpc.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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}"