-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (76 loc) · 2.63 KB
/
terraform-dev.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Deploying in dev environment via Terraform
on:
push:
branches:
- main
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_BUCKET: ${{ secrets.S3_BUCKET }}
DYNAMODB: ${{ secrets.DYNAMODB }}
TF_VAR_database_username: ${{ secrets.TF_VAR_DATABASE_USERNAME }}
TF_VAR_database_password: ${{ secrets.TF_VAR_DATABASE_PASSWORD }}
jobs:
tf_init:
name: Terraform Init
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.7
- name: Terraform Init
run: terraform init -backend-config="bucket=$S3_BUCKET" -backend-config="region=$S3_REGION" -backend-config="dynamodb_table=$DYNAMODB"
- name: Terraform Workspace
run: terraform workspace new dev 2> /dev/null || terraform workspace select dev
- name: Terraform Validate
run: terraform validate
tf_plan:
name: Terraform Plan
needs: [tf_init]
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.7
- name: Terraform Init
run: terraform init -backend-config="bucket=$S3_BUCKET" -backend-config="region=$S3_REGION" -backend-config="dynamodb_table=$DYNAMODB"
- name: Terraform Workspace
run: terraform workspace new dev 2> /dev/null || terraform workspace select dev
- name: Terraform Plan
run: terraform plan -input=false -out=terraform-plan-dev
- name: Upload Terraform Plan
uses: actions/upload-artifact@v2
with:
name: terraform-plan-dev
path: terraform-plan-dev
tf_apply:
name: Terraform Apply
needs: [tf_plan]
runs-on: ubuntu-latest
environment: dev-manual
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.7
- name: Terraform Init
run: terraform init -backend-config="bucket=$S3_BUCKET" -backend-config="region=$S3_REGION" -backend-config="dynamodb_table=$DYNAMODB"
- name: Terraform Workspace
run: terraform workspace new dev 2> /dev/null || terraform workspace select dev
- name: Download Terraform Plan
uses: actions/download-artifact@v2
with:
name: terraform-plan-dev
- name: Terraform Apply
run: terraform apply -auto-approve terraform-plan-dev