Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Terraform CI

on:
push:
branches: main
pull_request:

jobs:
validate-terraform:
name: Validate Terraform
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1

- name: Check for terraform version mismatch
run: |
DOTFILE_VERSION=$(cat .terraform-version)
TERRAFORM_IMAGE_REFERENCES=$(grep "uses: docker://hashicorp/terraform" .github/workflows/main.yml | grep -v TERRAFORM_IMAGE_REFERENCES | wc -l | tr -d ' ')
if [ "$(grep "docker://hashicorp/terraform:${DOTFILE_VERSION}" .github/workflows/main.yml | wc -l | tr -d ' ')" != "$TERRAFORM_IMAGE_REFERENCES" ]
then
echo -e "\033[1;31mError: terraform version in .terraform-version file does not match docker://hashicorp/terraform versions in .github/workflows/main.yml"
exit 1
fi

- name: Run a Terraform init
uses: docker://hashicorp/terraform:1.1.7
with:
entrypoint: terraform
args: init

- name: Run a Terraform validate
uses: docker://hashicorp/terraform:1.1.7
with:
entrypoint: terraform
args: validate

- name: Run a Terraform format check
uses: docker://hashicorp/terraform:1.1.7
with:
entrypoint: terraform
args: fmt -check=true -diff=true
validate-terraform-docs:
name: Validate Terraform Docs
needs: validate-terraform
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Generate Terraform docs
uses: terraform-docs/[email protected]
with:
working-dir: .
config-file: .terraform-docs.yml
output-file: README.md
output-method: inject
fail-on-diff: true