From 19f9f4c95eb2c5a21092529b4564eeb938ae65b0 Mon Sep 17 00:00:00 2001 From: David John Arnold Jr Date: Wed, 26 Mar 2025 22:03:39 -0700 Subject: [PATCH] updating docs (#1) --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/README.md b/README.md index 578279a..f4c0871 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,106 @@ This action has no inputs. ## Usage Examples +### Basic Validation +```yaml +steps: + - name: Checkout code + uses: CSVD/gh-actions-checkout@v4 + + - name: Setup Terraform + uses: CSVD/gh-actions-setup-terraform@v2 + with: + terraform_version: '1.7.3' + + - name: Validate Terraform Configuration + id: validate + uses: CSVD/terraform-validate@v1 + with: + working-directory: './terraform' + + - name: Check Validation Result + if: steps.validate.outputs.is_valid != 'true' + run: | + echo "Validation errors found:" + echo "${{ steps.validate.outputs.stderr }}" + exit 1 +``` + +### Validation with Backend Config +```yaml +steps: + - name: Validate with Backend Config + id: validate + uses: CSVD/terraform-validate@v1 + with: + working-directory: './environments/prod' + backend-config: | + region=us-east-1 + bucket=my-terraform-state + key=prod/terraform.tfstate + + - name: Show Validation Output + run: | + echo "Validation stdout:" + echo "${{ steps.validate.outputs.stdout }}" +``` + +### Validation with Variables File +```yaml +steps: + - name: Validate with Variables + id: validate + uses: CSVD/terraform-validate@v1 + with: + working-directory: './modules/app' + var-file: './environments/test.tfvars' +``` + +### Complete Workflow with Tests +```yaml +name: Terraform Quality Checks + +on: + pull_request: + paths: + - '**.tf' + - '**.tfvars' + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: CSVD/gh-actions-checkout@v4 + + - name: Setup Terraform + uses: CSVD/gh-actions-setup-terraform@v2 + with: + terraform_version: '1.7.3' + + - name: Validate and Test + id: validate + uses: CSVD/terraform-validate@v1 + with: + working-directory: './terraform' + var-file: './config/dev.tfvars' + + - name: Process Results + run: | + if [[ "${{ steps.validate.outputs.is_valid }}" != "true" ]]; then + echo "::error::Validation failed" + echo "${{ steps.validate.outputs.stderr }}" + exit 1 + fi + + if [[ "${{ steps.validate.outputs.tests_passed }}" != "true" ]]; then + echo "::error::Tests failed" + echo "${{ steps.validate.outputs.stderr }}" + exit 1 + fi + + echo "All validation and tests passed!" +``` ## Requirements - Terraform must be installed in the runner environment (typically using `hashicorp/setup-terraform` action)