Terraform test GH actions #96
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 test GH actions" | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'terraform/**' | |
pull_request: | |
branches: | |
- main | |
paths: | |
- 'terraform/**' | |
workflow_dispatch: # Manually trigger the workflow | |
env: | |
TF_LOG: INFO | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE }} | |
jobs: | |
terraform: | |
name: "Terraform Infrastructure Change Management" | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./terraform | |
steps: | |
- name: Checkout the repository to the runner | |
uses: actions/checkout@v2 | |
- name: Setup Terraform with specified version on the runner | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: 1.3.0 | |
- name: Terraform init | |
id: init | |
run: terraform init -backend-config="bucket=${BUCKET_TF_STATE}" | |
- name: Terraform format | |
id: fmt | |
run: terraform fmt -check | |
- name: Terraform validate | |
id: validate | |
run: terraform validate | |
- name: Terraform plan | |
id: plan | |
run: terraform plan -no-color -input=false | |
- name: Terraform apply | |
id: apply | |
run: terraform apply --auto-approve | |
- name: Terraform destroy | |
id: destroy | |
run: terraform destroy --auto-approve |