Terraform_deploy #9
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_deploy | |
on: | |
# push: | |
# branches: | |
# - main | |
# paths: | |
# - 'src/infrastructure/**' | |
workflow_dispatch: | |
inputs: | |
terraform_action: | |
type: choice | |
description: select terraform action | |
options: | |
- apply | |
- destroy | |
required: true | |
jobs: | |
dev: | |
name: dev | |
environment: DEV | |
runs-on: ubuntu-latest | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: us-east-1 | |
defaults: | |
run: | |
working-directory: src/infrastracture | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
#- name: pre-init file | |
#run: ./format_validate_all.sh | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.0.1 | |
- name: Terraform Format | |
id: fmt | |
run: terraform fmt -check | |
- name: Terraform Init | |
id: init | |
# run: terraform init -backend-config=providers.tfvars | |
run: terraform init -var-file="./env/dev/.terraform.tfvars" -backend-config="./env/dev/backend.tfvars" | |
- name: Terraform Plan | |
id: plan | |
run: terraform plan -var-file="./env/dev/.terraform.tfvars" | |
- name: Terraform Apply | |
if: ${{ github.event.inputs.terraform_action == 'apply' }} | |
run: terraform apply -var-file="./env/dev/.terraform.tfvars" --auto-approve | |
- name: Terraform Destroy | |
if: ${{ github.event.inputs.terraform_action == 'destroy' }} | |
run: terraform destroy --auto-approve -var-file="./env/dev/.terraform.tfvars" | |
staging: | |
name: staging | |
environment: STAGING | |
runs-on: ubuntu-latest | |
needs: dev | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }} | |
AWS_REGION: us-east-1 | |
defaults: | |
run: | |
working-directory: src/infrastracture | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v2 | |
#- name: pre-init file | |
# run: bash ./format_validate_all.sh | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.0.1 | |
terraform_wrapper: false | |
- name: Terraform Format | |
id: fmt | |
run: terraform fmt -check | |
- name: Terraform Init | |
id: init | |
run: terraform init -var-file="./env/staging/.terraform.tfvars" -backend-config="./env/staging/backend.tfvars" | |
- name: Terraform Plan | |
id: plan | |
run: terraform plan -var-file="./env/staging/.terraform.tfvars" | |
- name: Terraform Apply | |
if: ${{ github.event.inputs.terraform_action == 'apply' }} | |
run: terraform apply -var-file="./env/staging/.terraform.tfvars" --auto-approve | |
- name: Terraform Destroy | |
if: ${{ github.event.inputs.terraform_action == 'destroy' }} | |
run: terraform destroy --auto-approve -var-file="./env/staging/.terraform.tfvars" | |
prod: | |
name: prod | |
environment: PROD | |
runs-on: ubuntu-latest | |
needs: dev | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }} | |
AWS_REGION: us-east-1 | |
defaults: | |
run: | |
working-directory: src/infrastracture | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v2 | |
#- name: pre-init file | |
# run: bash ./format_validate_all.sh | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.0.1 | |
terraform_wrapper: false | |
- name: Terraform Format | |
id: fmt | |
run: terraform fmt -check | |
- name: Terraform Init | |
id: init | |
run: terraform init -var-file="./env/prod/.terraform.tfvars" -backend-config="./env/prod/backend.tfvars" | |
- name: Terraform Plan | |
id: plan | |
run: terraform plan -var-file="./env/prod/.terraform.tfvars" | |
- name: Terraform Apply | |
if: ${{ github.event.inputs.terraform_action == 'apply' }} | |
run: terraform apply -var-file="./env/prod/.terraform.tfvars" --auto-approve | |
- name: Terraform Destroy | |
if: ${{ github.event.inputs.terraform_action == 'destroy' }} | |
run: terraform destroy --auto-approve -var-file="./env/prod/.terraform.tfvars" | |