Skip to content

Commit

Permalink
feat: add terraform test command
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiehrhardt committed Oct 31, 2023
1 parent c2d6f1f commit abca177
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,29 @@ jobs:
destroy: ${{ matrix.destroy }}
directory: "test/terraform"

test-test:
name: Test Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Test
uses: "./"
with:
directory: "test/terraform"
test-directory: "test/terraform"
format: false
validate: false
plan: false
test: true

release:
name: Release
needs:
- test-setup
- test-args
- test-jobs
- test-test
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
59 changes: 36 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

Expand All @@ -26,7 +26,7 @@ jobs:
uses: actions/checkout@v4
- name: Deploy With Value 1
uses: "infinite-automations/terraform-all-in-one@v1.1.0"
with:
with:
directory: "./terraform"
apply: true
env:
Expand All @@ -36,17 +36,28 @@ jobs:
echo "Running test 1..."
- name: Deploy With Value 2
uses: "infinite-automations/terraform-all-in-one@v1.1.0"
with:
with:
directory: "./terraform"
apply: true
env:
TF_VAR_my_var: "value2"
- name: Run Test 2
run: |
echo "Running test 2..."
- name: Run Test 3
uses: "infinite-automations/terraform-all-in-one@v1.1.0"
with:
directory: "./terraform"
test-directory: "./terraform"
setup: false
init: false
format: false
validate: false
plan: false
test: true
- name: Destroy
uses: "infinite-automations/terraform-all-in-one@v1.1.0"
with:
with:
directory: "./terraform"
setup: false
init: false
Expand All @@ -61,25 +72,27 @@ You can configure additional command arguments with inputs.
## Inputs
| Input Name | Description | Required | Default |
| ----------------- | ----------------------------------------------------------------- | -------- | --------- |
| directory | The directory where the Terraform configuration files are located | false | . |
| terraform-version | The version of Terraform to use | false | latest |
| plan-file | The path to the plan file | false | plan.json |
| common-args | The arguments to pass to all terraform commands | false | |
| init-args | The arguments to pass to terraform init | false | |
| validate-args | The arguments to pass to terraform validate | false | |
| fmt-args | The arguments to pass to terraform fmt | false | -check |
| plan-args | The arguments to pass to terraform plan | false | |
| apply-args | The arguments to pass to terraform apply | false | |
| destroy-args | The arguments to pass to terraform destroy | false | |
| setup | Whether to setup | false | true |
| init | Whether to init | false | true |
| format | Whether to format | false | true |
| validate | Whether to validate | false | true |
| plan | Whether to plan | false | true |
| apply | Whether to apply | false | false |
| destroy | Whether to destroy | false | false |
| Input Name | Description | Required | Default |
| ----------------- | ---------------------------------------------------------------------- | -------- | --------- |
| directory | The directory where the Terraform configuration files are located | false | . |
| test-directory | The directory where the Terraform test configuration files are located | false | . |
| terraform-version | The version of Terraform to use | false | latest |
| plan-file | The path to the plan file | false | plan.json |
| common-args | The arguments to pass to all terraform commands | false | |
| init-args | The arguments to pass to terraform init | false | |
| validate-args | The arguments to pass to terraform validate | false | |
| fmt-args | The arguments to pass to terraform fmt | false | -check |
| plan-args | The arguments to pass to terraform plan | false | |
| apply-args | The arguments to pass to terraform apply | false | |
| destroy-args | The arguments to pass to terraform destroy | false | |
| setup | Whether to setup | false | true |
| init | Whether to init | false | true |
| format | Whether to format | false | true |
| validate | Whether to validate | false | true |
| test | Whether to test | false | false |
| plan | Whether to plan | false | true |
| apply | Whether to apply | false | false |
| destroy | Whether to destroy | false | false |
## Outputs
Expand Down
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
description: "The directory where the Terraform configuration files are located"
required: false
default: "."
test-directory:
description: "The directory where the Terraform test configuration files are located"
required: false
default: "."
terraform-version:
description: "The version of Terraform to use"
required: false
Expand All @@ -31,6 +35,10 @@ inputs:
description: "The arguments to pass to terraform fmt"
required: false
default: "-check"
test-args:
description: "The arguments to pass to terraform test"
required: false
default: ""
plan-args:
description: "The arguments to pass to terraform plan"
required: false
Expand Down Expand Up @@ -59,6 +67,10 @@ inputs:
description: "Whether to validate"
required: false
default: "true"
test:
description: "Whether to test"
required: false
default: "false"
plan:
description: "Whether to plan"
required: false
Expand Down Expand Up @@ -100,6 +112,11 @@ runs:
run: terraform validate ${{ inputs.common-args }} ${{ inputs.validate-args }}
working-directory: ${{ inputs.directory }}
shell: bash
- name: Terraform Test
if: ${{ inputs.test == 'true' }}
run: terraform test ${{ inputs.common-args }} ${{ inputs.test-args }}
working-directory: ${{ inputs.test-directory }}
shell: bash
- name: Terraform Plan
if: ${{ inputs.plan == 'true' }}
run: terraform plan ${{ inputs.common-args }} ${{ inputs.plan-args }} -out ${{ inputs.plan-file }}
Expand Down
1 change: 1 addition & 0 deletions test/terraform/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run "setup" {}

0 comments on commit abca177

Please sign in to comment.