Skip to content

Commit

Permalink
Merge pull request #2 from buildrun-tech/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
brunograna authored May 23, 2024
2 parents 43352be + 852b121 commit 94ccb7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
38 changes: 24 additions & 14 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Read destroy configuration
id: read-destroy-config
run: |
DESTROY_DEV="$(jq -r '.dev' ./infra/destroy_config.json)"
DESTROY_PROD="$(jq -r '.prod' ./infra/destroy_config.json)"
echo "::set-output name=destroy_dev::$DESTROY_DEV"
echo "::set-output name=destroy_prod::$DESTROY_PROD"
- name: Terraform Init
run: |
cd infra && terraform init \
Expand All @@ -41,41 +49,43 @@ jobs:
- 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 Destroy for Dev
if: steps.read-destroy-config.outputs.destroy_dev == 'true' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
id: terraform-destroy-dev
run: cd infra &&
terraform workspace select dev || terraform workspace new dev &&
terraform destroy -var-file="./envs/dev/terraform.tfvars" -auto-approve

- name: Terraform Plan for Dev
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
if: steps.read-destroy-config.outputs.destroy_dev != 'true' && 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'
if: steps.read-destroy-config.outputs.destroy_dev != 'true' && 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 Destroy for Prod
if: steps.read-destroy-config.outputs.destroy_prod == 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
id: terraform-destroy-prod
run: cd infra &&
terraform workspace select prod || terraform workspace new prod &&
terraform destroy -var-file="./envs/prod/terraform.tfvars" -auto-approve

- name: Terraform Plan for Prod
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
if: steps.read-destroy-config.outputs.destroy_prod != 'true' && 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'
if: steps.read-destroy-config.outputs.destroy_prod != 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
id: terraform-apply-prod
run: cd infra &&
terraform workspace select prod || terraform workspace new prod &&
Expand Down
4 changes: 4 additions & 0 deletions infra/destroy_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dev": true,
"prod": false
}

0 comments on commit 94ccb7e

Please sign in to comment.