Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add terraform test command #2

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
matrix:
format: ["true", "false"]
validate: ["true", "false"]
test: ["true", "false"]
plan: ["true", "false"]
apply: ["true", "false"]
destroy: ["true", "false"]
Expand All @@ -77,6 +78,7 @@ jobs:
init: true
format: ${{ matrix.format }}
validate: ${{ matrix.validate }}
test: ${{ matrix.test }}
plan: ${{ matrix.plan }}
apply: ${{ matrix.apply }}
destroy: ${{ matrix.destroy }}
Expand All @@ -88,6 +90,7 @@ jobs:
init: true
format: ${{ matrix.format }}
validate: ${{ matrix.validate }}
test: ${{ matrix.test }}
plan: ${{ matrix.plan }}
apply: ${{ matrix.apply }}
destroy: ${{ matrix.destroy }}
Expand All @@ -99,17 +102,40 @@ jobs:
init: false
format: ${{ matrix.format }}
validate: ${{ matrix.validate }}
test: ${{ matrix.test }}
plan: ${{ matrix.plan }}
apply: ${{ matrix.apply }}
destroy: ${{ matrix.destroy }}
directory: "test/terraform"

test-terraform-test:
name: Test terraform test
runs-on: ubuntu-latest
strategy:
matrix:
test-args: ["-json", ""]
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Test
uses: "./"
with:
directory: "test/terraform"
test-directory: "test/terraform"
m4s-b3n marked this conversation as resolved.
Show resolved Hide resolved
test-args: ${{ matrix.test-args }}
format: false
validate: false
plan: false
test: true

release:
name: Release
needs:
- test-setup
- test-args
- test-jobs
- test-terraform-test
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
6 changes: 3 additions & 3 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
{
"file": "README.md",
"hasChanged": true,
"numMatches": 3,
"numReplacements": 3
"numMatches": 4,
"numReplacements": 4
}
],
"countMatches": true
Expand All @@ -48,4 +48,4 @@
],
"@semantic-release/github"
]
}
}
59 changes: 34 additions & 25 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,23 @@ 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..."
uses: "infinite-automations/terraform-all-in-one@v1.1.0"
with:
directory: "./terraform"
test-directory: "./terraform"
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 +67,28 @@ 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 |
| test-args | The arguments to pass to terraform test | false | |
| 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" {}