-
Notifications
You must be signed in to change notification settings - Fork 1
61 lines (48 loc) · 1.61 KB
/
terraform.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
61
name: Terraform
on:
push:
branches:
- main
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Echo AWS Access Key (Debug Step)
run: echo ${{ secrets.AWS_ACCESS_KEY_ID }}
- name: Verify AWS Secrets Presence (Debug Step)
run: |
if [ -z "${{ secrets.AWS_ACCESS_KEY_ID }}" ]; then
echo "AWS_ACCESS_KEY_ID secret is not set"
exit 1
fi
if [ -z "${{ secrets.AWS_SECRET_ACCESS_KEY }}" ]; then
echo "AWS_SECRET_ACCESS_KEY secret is not set"
exit 1
fi
echo "AWS secrets are set"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Verify AWS credentials
run: aws sts get-caller-identity
- name: Initialize Terraform
run: terraform init
working-directory: terraform
- name: Plan Terraform
run: terraform plan -out=tfplan
working-directory: terraform
- name: Apply Terraform
run: terraform apply -auto-approve tfplan
working-directory: terraform
- name: Wait for 2 minutes
run: sleep 120 # 300 seconds equals 5 minutes
- name: Destroy Terraform
run: terraform destroy -auto-approve
working-directory: terraform