Skip to content

Commit d33a74d

Browse files
committed
feat: add terraform test command
1 parent c2d6f1f commit d33a74d

File tree

5 files changed

+81
-28
lines changed

5 files changed

+81
-28
lines changed

.github/workflows/test-and-release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
matrix:
6464
format: ["true", "false"]
6565
validate: ["true", "false"]
66+
test: ["true", "false"]
6667
plan: ["true", "false"]
6768
apply: ["true", "false"]
6869
destroy: ["true", "false"]
@@ -77,6 +78,7 @@ jobs:
7778
init: true
7879
format: ${{ matrix.format }}
7980
validate: ${{ matrix.validate }}
81+
test: ${{ matrix.test }}
8082
plan: ${{ matrix.plan }}
8183
apply: ${{ matrix.apply }}
8284
destroy: ${{ matrix.destroy }}
@@ -88,6 +90,7 @@ jobs:
8890
init: true
8991
format: ${{ matrix.format }}
9092
validate: ${{ matrix.validate }}
93+
test: ${{ matrix.test }}
9194
plan: ${{ matrix.plan }}
9295
apply: ${{ matrix.apply }}
9396
destroy: ${{ matrix.destroy }}
@@ -99,17 +102,40 @@ jobs:
99102
init: false
100103
format: ${{ matrix.format }}
101104
validate: ${{ matrix.validate }}
105+
test: ${{ matrix.test }}
102106
plan: ${{ matrix.plan }}
103107
apply: ${{ matrix.apply }}
104108
destroy: ${{ matrix.destroy }}
105109
directory: "test/terraform"
106110

111+
test-terraform-test:
112+
name: Test terraform test
113+
runs-on: ubuntu-latest
114+
strategy:
115+
matrix:
116+
test-args: ["-json", ""]
117+
fail-fast: true
118+
steps:
119+
- name: Checkout
120+
uses: actions/checkout@v4
121+
- name: Test
122+
uses: "./"
123+
with:
124+
directory: "test/terraform"
125+
test-directory: "test/terraform"
126+
test-args: ${{ matrix.test-args }}
127+
format: false
128+
validate: false
129+
plan: false
130+
test: true
131+
107132
release:
108133
name: Release
109134
needs:
110135
- test-setup
111136
- test-args
112137
- test-jobs
138+
- test-terraform-test
113139
runs-on: ubuntu-latest
114140
steps:
115141
- name: Checkout

.releaserc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
{
2828
"file": "README.md",
2929
"hasChanged": true,
30-
"numMatches": 3,
31-
"numReplacements": 3
30+
"numMatches": 4,
31+
"numReplacements": 4
3232
}
3333
],
3434
"countMatches": true
@@ -48,4 +48,4 @@
4848
],
4949
"@semantic-release/github"
5050
]
51-
}
51+
}

README.md

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
branches: ["main"]
1414
pull_request:
1515
branches: ["main"]
16-
16+
1717
permissions:
1818
contents: read
1919

@@ -26,7 +26,7 @@ jobs:
2626
uses: actions/checkout@v4
2727
- name: Deploy With Value 1
2828
uses: "infinite-automations/[email protected]"
29-
with:
29+
with:
3030
directory: "./terraform"
3131
apply: true
3232
env:
@@ -36,17 +36,23 @@ jobs:
3636
echo "Running test 1..."
3737
- name: Deploy With Value 2
3838
uses: "infinite-automations/[email protected]"
39-
with:
39+
with:
4040
directory: "./terraform"
4141
apply: true
4242
env:
4343
TF_VAR_my_var: "value2"
4444
- name: Run Test 2
45-
run: |
46-
echo "Running test 2..."
45+
uses: "infinite-automations/[email protected]"
46+
with:
47+
directory: "./terraform"
48+
test-directory: "./terraform"
49+
format: false
50+
validate: false
51+
plan: false
52+
test: true
4753
- name: Destroy
4854
uses: "infinite-automations/[email protected]"
49-
with:
55+
with:
5056
directory: "./terraform"
5157
setup: false
5258
init: false
@@ -61,25 +67,28 @@ You can configure additional command arguments with inputs.
6167
6268
## Inputs
6369
64-
| Input Name | Description | Required | Default |
65-
| ----------------- | ----------------------------------------------------------------- | -------- | --------- |
66-
| directory | The directory where the Terraform configuration files are located | false | . |
67-
| terraform-version | The version of Terraform to use | false | latest |
68-
| plan-file | The path to the plan file | false | plan.json |
69-
| common-args | The arguments to pass to all terraform commands | false | |
70-
| init-args | The arguments to pass to terraform init | false | |
71-
| validate-args | The arguments to pass to terraform validate | false | |
72-
| fmt-args | The arguments to pass to terraform fmt | false | -check |
73-
| plan-args | The arguments to pass to terraform plan | false | |
74-
| apply-args | The arguments to pass to terraform apply | false | |
75-
| destroy-args | The arguments to pass to terraform destroy | false | |
76-
| setup | Whether to setup | false | true |
77-
| init | Whether to init | false | true |
78-
| format | Whether to format | false | true |
79-
| validate | Whether to validate | false | true |
80-
| plan | Whether to plan | false | true |
81-
| apply | Whether to apply | false | false |
82-
| destroy | Whether to destroy | false | false |
70+
| Input Name | Description | Required | Default |
71+
| ----------------- | ---------------------------------------------------------------------- | -------- | --------- |
72+
| directory | The directory where the Terraform configuration files are located | false | . |
73+
| test-directory | The directory where the Terraform test configuration files are located | false | . |
74+
| terraform-version | The version of Terraform to use | false | latest |
75+
| plan-file | The path to the plan file | false | plan.json |
76+
| common-args | The arguments to pass to all terraform commands | false | |
77+
| init-args | The arguments to pass to terraform init | false | |
78+
| validate-args | The arguments to pass to terraform validate | false | |
79+
| fmt-args | The arguments to pass to terraform fmt | false | -check |
80+
| test-args | The arguments to pass to terraform test | false | |
81+
| plan-args | The arguments to pass to terraform plan | false | |
82+
| apply-args | The arguments to pass to terraform apply | false | |
83+
| destroy-args | The arguments to pass to terraform destroy | false | |
84+
| setup | Whether to setup | false | true |
85+
| init | Whether to init | false | true |
86+
| format | Whether to format | false | true |
87+
| validate | Whether to validate | false | true |
88+
| test | Whether to test | false | false |
89+
| plan | Whether to plan | false | true |
90+
| apply | Whether to apply | false | false |
91+
| destroy | Whether to destroy | false | false |
8392
8493
## Outputs
8594

action.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
description: "The directory where the Terraform configuration files are located"
88
required: false
99
default: "."
10+
test-directory:
11+
description: "The directory where the Terraform test configuration files are located"
12+
required: false
13+
default: "."
1014
terraform-version:
1115
description: "The version of Terraform to use"
1216
required: false
@@ -31,6 +35,10 @@ inputs:
3135
description: "The arguments to pass to terraform fmt"
3236
required: false
3337
default: "-check"
38+
test-args:
39+
description: "The arguments to pass to terraform test"
40+
required: false
41+
default: ""
3442
plan-args:
3543
description: "The arguments to pass to terraform plan"
3644
required: false
@@ -59,6 +67,10 @@ inputs:
5967
description: "Whether to validate"
6068
required: false
6169
default: "true"
70+
test:
71+
description: "Whether to test"
72+
required: false
73+
default: "false"
6274
plan:
6375
description: "Whether to plan"
6476
required: false
@@ -100,6 +112,11 @@ runs:
100112
run: terraform validate ${{ inputs.common-args }} ${{ inputs.validate-args }}
101113
working-directory: ${{ inputs.directory }}
102114
shell: bash
115+
- name: Terraform Test
116+
if: ${{ inputs.test == 'true' }}
117+
run: terraform test ${{ inputs.common-args }} ${{ inputs.test-args }}
118+
working-directory: ${{ inputs.test-directory }}
119+
shell: bash
103120
- name: Terraform Plan
104121
if: ${{ inputs.plan == 'true' }}
105122
run: terraform plan ${{ inputs.common-args }} ${{ inputs.plan-args }} -out ${{ inputs.plan-file }}

test/terraform/main.tftest.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run "setup" {}

0 commit comments

Comments
 (0)