ci: add terraform validate workflow #10
Workflow file for this run
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 | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
terraform-fmt: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Set $TERRAFORM_VERSION | |
working-directory: "./terraform" | |
run: echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> "$GITHUB_ENV" | |
- name: Setup Terraform | |
uses: hashicorp/[email protected] | |
with: | |
terraform_version: ${{ env.TERRAFORM_VERSION }} | |
- name: Run terraform fmt | |
working-directory: "./terraform" | |
run: terraform fmt -check -recursive | |
terraform-validate: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Configure AWS Credentials | |
uses: aws-actions/[email protected] | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Set $TERRAFORM_VERSION | |
working-directory: "./terraform" | |
run: echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> "$GITHUB_ENV" | |
- name: Setup Terraform | |
uses: hashicorp/[email protected] | |
with: | |
terraform_version: ${{ env.TERRAFORM_VERSION }} | |
- name: Run terraform init | |
working-directory: "./terraform" | |
run: | | |
terraform init \ | |
-backend-config='bucket=${{ secrets.S3_TFSTATE_BUCKET }}' \ | |
-backend-config='key=${{ secrets.S3_TFSTATE_KEY }}' \ | |
-backend-config='region=${{ secrets.S3_TFSTATE_REGION }}' | |
- name: Run terraform validate | |
working-directory: "./terraform" | |
run: terraform validate | |
terraform-plan: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Configure AWS Credentials | |
uses: aws-actions/[email protected] | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Set $TERRAFORM_VERSION | |
working-directory: "./terraform" | |
run: echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> "$GITHUB_ENV" | |
- name: Setup Terraform | |
uses: hashicorp/[email protected] | |
with: | |
terraform_version: ${{ env.TERRAFORM_VERSION }} | |
- name: Run terraform init | |
working-directory: "./terraform" | |
run: | | |
terraform init \ | |
-backend-config='bucket=${{ secrets.S3_TFSTATE_BUCKET }}' \ | |
-backend-config='key=${{ secrets.S3_TFSTATE_KEY }}' \ | |
-backend-config='region=${{ secrets.S3_TFSTATE_REGION }}' | |
- name: Run terraform plan | |
working-directory: "./terraform" | |
run: terraform plan |