cd: debug #29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |