-
Notifications
You must be signed in to change notification settings - Fork 2
82 lines (68 loc) · 2.79 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Terraform Deployment
on:
push:
branches:
- develop
- main
jobs:
terraform:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.8.3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}
- name: Terraform Init
run: |
cd infra && terraform init \
-backend-config="bucket=${{ vars.TERRAFORM_S3_STATEFILE_BUCKET }}" \
-backend-config="key=${{ github.event.repository.name }}" \
-backend-config="region=${{ env.AWS_REGION }}" \
-backend-config="dynamodb_table=${{ vars.TERRAFORM_DYNAMODB_LOCK_TABLE }}"
- name: Terraform Validate
run: terraform validate
# - name: Terraform Create Dev Workspace
# if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
# id: select-dev-workspace
# run: |
# terraform workspace list | grep -q "dev" || terraform workspace new dev
- name: Terraform Plan for Dev
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
id: terraform-plan-dev
run: cd infra &&
terraform workspace select dev || terraform workspace new dev &&
terraform plan -var-file="./envs/dev/terraform.tfvars" -out=dev.plan
- name: Terraform Apply for Dev
id: terraform-apply-dev
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
run: cd infra &&
terraform workspace select dev || terraform workspace new dev &&
terraform apply "dev.plan"
# - name: Terraform Create Prod Workspace
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# id: select-prod-workspace
# run: |
# terraform workspace list | grep -q "prod" || terraform workspace new prod
- name: Terraform Plan for Prod
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
id: terraform-plan-prod
run: cd infra &&
terraform workspace select prod || terraform workspace new prod &&
terraform plan -var-file="./envs/prod/terraform.tfvars" -out=prod.plan
- name: Terraform Apply for Prod
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
id: terraform-apply-prod
run: cd infra &&
terraform workspace select prod || terraform workspace new prod &&
terraform apply "prod.plan"