Skip to content

Commit 4e1aa58

Browse files
authored
Merge pull request #380 from dflook/early-eval
Support OpenTofu early initialisation variables
2 parents 1b64573 + a774780 commit 4e1aa58

37 files changed

+595
-72
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Test OpenTofu early eval
2+
3+
on:
4+
- pull_request
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
s3-backend:
11+
runs-on: ubuntu-24.04
12+
name: Plan with early eval
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
env:
17+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
18+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
persist-credentials: false
25+
26+
- name: tofu plan
27+
uses: ./tofu-plan
28+
id: plan
29+
with:
30+
path: tests/workflows/test-early-eval/s3
31+
variables: |
32+
passphrase = "tofuqwertyuiopasdfgh"
33+
34+
- name: Verify outputs
35+
env:
36+
JSON_PLAN_PATH: ${{ steps.plan.outputs.json_plan_path }}
37+
run: |
38+
if [[ ! -f "$JSON_PLAN_PATH" ]]; then
39+
echo "::error:: json_plan_path not set correctly"
40+
exit 1
41+
fi
42+
43+
- name: tofu apply
44+
uses: ./tofu-apply
45+
with:
46+
path: tests/workflows/test-early-eval/s3
47+
variables: |
48+
passphrase = "tofuqwertyuiopasdfgh"
49+
50+
- name: Create workspace
51+
uses: ./tofu-new-workspace
52+
with:
53+
path: tests/workflows/test-early-eval/s3
54+
workspace: test-workspace
55+
variables: |
56+
passphrase = "tofuqwertyuiopasdfgh"
57+
58+
- name: Create workspace again
59+
uses: ./tofu-new-workspace
60+
with:
61+
path: tests/workflows/test-early-eval/s3
62+
workspace: test-workspace
63+
variables: |
64+
passphrase = "tofuqwertyuiopasdfgh"
65+
66+
- name: Destroy workspace
67+
uses: ./tofu-destroy-workspace
68+
with:
69+
path: tests/workflows/test-early-eval/s3
70+
workspace: test-workspace
71+
variables: |
72+
passphrase = "tofuqwertyuiopasdfgh"

.github/workflows/test-version.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ jobs:
611611
run: |
612612
echo "The terraform version was $DETECTED_TERRAFORM_VERSION"
613613
614-
if [[ "$DETECTED_TERRAFORM_VERSION" != *"1.11"* ]]; then
614+
if [[ "$DETECTED_TERRAFORM_VERSION" != *"1.12"* ]]; then
615615
echo "::error:: Latest version was not used"
616616
exit 1
617617
fi
@@ -632,7 +632,7 @@ jobs:
632632
run: |
633633
echo "The terraform version was $DETECTED_TERRAFORM_VERSION"
634634
635-
if [[ "$DETECTED_TERRAFORM_VERSION" != *"1.11"* ]]; then
635+
if [[ "$DETECTED_TERRAFORM_VERSION" != *"1.12"* ]]; then
636636
echo "::error:: Latest version was not used"
637637
exit 1
638638
fi

.github/workflows/test.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ jobs:
119119
docs/*.md
120120
**/README.md
121121
122-
- name: ensure-sha-pinned-actions
123-
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@25ed13d0628a1601b4b44048e63cc4328ed03633 # v3
124-
with:
125-
allowlist: |
126-
actions/
127-
dflook/
128-
129122
- name: Lint Dockerfile
130123
uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
131124
with:

.github/zizmor.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
rules:
2+
unpinned-uses:
3+
config:
4+
policies:
5+
dflook/terraform-apply: ref-pin
6+
dflook/terraform-plan: ref-pin
7+
actions/*: ref-pin

docs-gen/action.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Input:
4545
deprecation_message: str = None
4646
show_in_docs: bool = True
4747
example: str = None
48+
available_in: list[Type[Terraform] | Type[OpenTofu]] = dataclasses.field(default_factory=lambda: [Terraform, OpenTofu])
4849

4950
def markdown(self, tool: Tool) -> str:
5051
if self.deprecation_message is None:
@@ -226,6 +227,8 @@ def markdown(self, tool: Tool) -> str:
226227
for input in self.inputs:
227228
if not input.show_in_docs:
228229
continue
230+
if tool not in input.available_in:
231+
continue
229232
s += text_chunk(input.markdown(tool))
230233

231234
if self.outputs:
@@ -264,7 +267,7 @@ def action_yaml(self, tool: Tool) -> str:
264267
if self.inputs:
265268
s += 'inputs:\n'
266269

267-
for input in self.inputs:
270+
for input in (input for input in self.inputs if tool in input.available_in):
268271
s += f' {input.name}:\n'
269272

270273
description = input.meta_description or input.description

docs-gen/actions/destroy_workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@
114114
workspace: ${{ github.head_ref }}
115115
```
116116
'''
117-
)
117+
)

docs-gen/actions/fmt.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import dataclasses
22

3-
from action import Action
3+
from action import Action, OpenTofu
44
from environment_variables.GITHUB_DOT_COM_TOKEN import GITHUB_DOT_COM_TOKEN
55
from environment_variables.TERRAFORM_CLOUD_TOKENS import TERRAFORM_CLOUD_TOKENS
66
from inputs.backend_config import backend_config
77
from inputs.backend_config_file import backend_config_file
88
from inputs.path import path
9+
from inputs.var_file import var_file
10+
from inputs.variables import variables
911
from inputs.workspace import workspace
1012

1113
fmt = Action(
@@ -20,6 +22,11 @@
2022
$ProductName workspace to inspect when discovering the $ProductName version to use, if the version is not otherwise specified.
2123
See [dflook/$ToolName-version](https://github.com/dflook/terraform-github-actions/tree/main/$ToolName-version#$ToolName-version-action) for details.
2224
'''),
25+
dataclasses.replace(variables, available_in=[OpenTofu], description='''
26+
Variables to set when initializing $ProductName. This should be valid $ProductName syntax - like a [variable definition file]($VariableDefinitionUrl).
27+
Variables set here override any given in `var_file`s.
28+
'''),
29+
dataclasses.replace(var_file, available_in=[OpenTofu]),
2330
dataclasses.replace(backend_config, description='''
2431
List of $ProductName backend config values, one per line. This is used for discovering the $ProductName version to use, if the version is not otherwise specified.
2532
See [dflook/$ToolName-version](https://github.com/dflook/terraform-github-actions/tree/main/$ToolName-version#$ToolName-version-action) for details.
@@ -70,4 +77,4 @@
7077
branch: automated-$ToolName-fmt
7178
```
7279
'''
73-
)
80+
)

docs-gen/actions/fmt_check.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import dataclasses
22

3-
from action import Action
3+
from action import Action, OpenTofu
44
from environment_variables.GITHUB_DOT_COM_TOKEN import GITHUB_DOT_COM_TOKEN
55
from environment_variables.TERRAFORM_CLOUD_TOKENS import TERRAFORM_CLOUD_TOKENS
66
from inputs.backend_config import backend_config
77
from inputs.backend_config_file import backend_config_file
88
from inputs.path import path
9+
from inputs.var_file import var_file
10+
from inputs.variables import variables
911
from inputs.workspace import workspace
1012
from outputs.failure_reason import failure_reason
1113

@@ -24,6 +26,11 @@
2426
$ProductName workspace to inspect when discovering the $ProductName version to use, if the version is not otherwise specified.
2527
See [dflook/$ToolName-version](https://github.com/dflook/terraform-github-actions/tree/main/$ToolName-version#$ToolName-version-action) for details.
2628
'''),
29+
dataclasses.replace(variables, available_in=[OpenTofu], description='''
30+
Variables to set when initializing $ProductName. This should be valid $ProductName syntax - like a [variable definition file]($VariableDefinitionUrl).
31+
Variables set here override any given in `var_file`s.
32+
'''),
33+
dataclasses.replace(var_file, available_in=[OpenTofu]),
2734
dataclasses.replace(backend_config, description='''
2835
List of $ProductName backend config values, one per line. This is used for discovering the $ProductName version to use, if the version is not otherwise specified.
2936
See [dflook/$ToolName-version](https://github.com/dflook/terraform-github-actions/tree/main/$ToolName-version#$ToolName-version-action) for details.
@@ -96,4 +103,4 @@
96103
run: echo "formatting check failed"
97104
```
98105
'''
99-
)
106+
)

docs-gen/actions/new_workspace.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dataclasses
22

3-
from action import Action
3+
from action import Action, OpenTofu
44
from environment_variables.GITHUB_DOT_COM_TOKEN import GITHUB_DOT_COM_TOKEN
55
from environment_variables.TERRAFORM_CLOUD_TOKENS import TERRAFORM_CLOUD_TOKENS
66
from environment_variables.TERRAFORM_HTTP_CREDENTIALS import TERRAFORM_HTTP_CREDENTIALS
@@ -9,6 +9,8 @@
99
from inputs.backend_config import backend_config
1010
from inputs.backend_config_file import backend_config_file
1111
from inputs.path import path
12+
from inputs.var_file import var_file
13+
from inputs.variables import variables
1214
from inputs.workspace import workspace
1315

1416
new_workspace = Action(
@@ -19,6 +21,12 @@
1921
inputs=[
2022
path,
2123
dataclasses.replace(workspace, description='The name of the $ProductName workspace to create.', required=True, default=None),
24+
dataclasses.replace(variables, available_in=[OpenTofu], description='''
25+
Variables to set when initializing $ProductName. This should be valid $ProductName syntax - like a [variable definition file]($VariableDefinitionUrl).
26+
27+
Variables set here override any given in `var_file`s.
28+
'''),
29+
dataclasses.replace(var_file, available_in=[OpenTofu]),
2230
backend_config,
2331
backend_config_file,
2432
],
@@ -62,4 +70,4 @@
6270
auto_approve: true
6371
```
6472
'''
65-
)
73+
)

docs-gen/actions/output.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dataclasses
22

3-
from action import Action
3+
from action import Action, OpenTofu
44
from environment_variables.GITHUB_DOT_COM_TOKEN import GITHUB_DOT_COM_TOKEN
55
from environment_variables.TERRAFORM_CLOUD_TOKENS import TERRAFORM_CLOUD_TOKENS
66
from environment_variables.TERRAFORM_HTTP_CREDENTIALS import TERRAFORM_HTTP_CREDENTIALS
@@ -9,6 +9,8 @@
99
from inputs.backend_config import backend_config
1010
from inputs.backend_config_file import backend_config_file
1111
from inputs.path import path
12+
from inputs.var_file import var_file
13+
from inputs.variables import variables
1214
from inputs.workspace import workspace
1315
from outputs.terraform_outputs import terraform_outputs
1416

@@ -20,8 +22,14 @@
2022
inputs=[
2123
path,
2224
dataclasses.replace(workspace, description='$ProductName workspace to get outputs from'),
25+
dataclasses.replace(variables, available_in=[OpenTofu], description='''
26+
Variables to set when initializing $ProductName. This should be valid $ProductName syntax - like a [variable definition file]($VariableDefinitionUrl).
27+
28+
Variables set here override any given in `var_file`s.
29+
'''),
30+
dataclasses.replace(var_file, available_in=[OpenTofu]),
2331
backend_config,
24-
backend_config_file,
32+
backend_config_file
2533
],
2634
environment_variables=[
2735
GITHUB_DOT_COM_TOKEN,
@@ -106,4 +114,4 @@
106114
The subnet-ids are subnet-053008016a2c1768c,subnet-07d4ce437c43eba2f,subnet-0a5f8c3a20023b8c0
107115
```
108116
'''
109-
)
117+
)

0 commit comments

Comments
 (0)