Skip to content

Commit 94ccb7e

Browse files
authored
Merge pull request #2 from buildrun-tech/develop
Develop
2 parents 43352be + 852b121 commit 94ccb7e

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

.github/workflows/terraform.yml

+24-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ jobs:
3030
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3131
aws-region: ${{ vars.AWS_REGION }}
3232

33+
- name: Read destroy configuration
34+
id: read-destroy-config
35+
run: |
36+
DESTROY_DEV="$(jq -r '.dev' ./infra/destroy_config.json)"
37+
DESTROY_PROD="$(jq -r '.prod' ./infra/destroy_config.json)"
38+
echo "::set-output name=destroy_dev::$DESTROY_DEV"
39+
echo "::set-output name=destroy_prod::$DESTROY_PROD"
40+
3341
- name: Terraform Init
3442
run: |
3543
cd infra && terraform init \
@@ -41,41 +49,43 @@ jobs:
4149
- name: Terraform Validate
4250
run: terraform validate
4351

44-
# - name: Terraform Create Dev Workspace
45-
# if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
46-
# id: select-dev-workspace
47-
# run: |
48-
# terraform workspace list | grep -q "dev" || terraform workspace new dev
52+
- name: Terraform Destroy for Dev
53+
if: steps.read-destroy-config.outputs.destroy_dev == 'true' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
54+
id: terraform-destroy-dev
55+
run: cd infra &&
56+
terraform workspace select dev || terraform workspace new dev &&
57+
terraform destroy -var-file="./envs/dev/terraform.tfvars" -auto-approve
4958

5059
- name: Terraform Plan for Dev
51-
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
60+
if: steps.read-destroy-config.outputs.destroy_dev != 'true' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
5261
id: terraform-plan-dev
5362
run: cd infra &&
5463
terraform workspace select dev || terraform workspace new dev &&
5564
terraform plan -var-file="./envs/dev/terraform.tfvars" -out=dev.plan
5665

5766
- name: Terraform Apply for Dev
5867
id: terraform-apply-dev
59-
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
68+
if: steps.read-destroy-config.outputs.destroy_dev != 'true' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
6069
run: cd infra &&
6170
terraform workspace select dev || terraform workspace new dev &&
6271
terraform apply "dev.plan"
6372

64-
# - name: Terraform Create Prod Workspace
65-
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
66-
# id: select-prod-workspace
67-
# run: |
68-
# terraform workspace list | grep -q "prod" || terraform workspace new prod
73+
- name: Terraform Destroy for Prod
74+
if: steps.read-destroy-config.outputs.destroy_prod == 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
75+
id: terraform-destroy-prod
76+
run: cd infra &&
77+
terraform workspace select prod || terraform workspace new prod &&
78+
terraform destroy -var-file="./envs/prod/terraform.tfvars" -auto-approve
6979

7080
- name: Terraform Plan for Prod
71-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
81+
if: steps.read-destroy-config.outputs.destroy_prod != 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
7282
id: terraform-plan-prod
7383
run: cd infra &&
7484
terraform workspace select prod || terraform workspace new prod &&
7585
terraform plan -var-file="./envs/prod/terraform.tfvars" -out=prod.plan
7686

7787
- name: Terraform Apply for Prod
78-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
88+
if: steps.read-destroy-config.outputs.destroy_prod != 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
7989
id: terraform-apply-prod
8090
run: cd infra &&
8191
terraform workspace select prod || terraform workspace new prod &&

infra/destroy_config.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dev": true,
3+
"prod": false
4+
}

0 commit comments

Comments
 (0)