Skip to content

Commit fd3626f

Browse files
committed
Add support for ephemeral variables in terraform >= 1.10.0
These must be specified again when applying a saved plan, but must not be specified in earlier versions of Terraform or OpenTofu
1 parent 3ec9e24 commit fd3626f

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

.github/workflows/test-apply.yaml

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ jobs:
934934
pull-requests: write
935935
env:
936936
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
937+
TERRAFORM_VERSION: "<1.10.0"
937938
steps:
938939
- name: Checkout
939940
uses: actions/checkout@v4
@@ -980,6 +981,47 @@ jobs:
980981
exit 1
981982
fi
982983
984+
deprecated_var_ephemeral:
985+
runs-on: ubuntu-24.04
986+
name: Nice error message for ephemeral var
987+
permissions:
988+
contents: read
989+
pull-requests: write
990+
env:
991+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
992+
TERRAFORM_VERSION: ">=1.10.0"
993+
steps:
994+
- name: Checkout
995+
uses: actions/checkout@v4
996+
with:
997+
persist-credentials: false
998+
999+
- name: Plan
1000+
uses: ./terraform-plan
1001+
with:
1002+
label: test-apply deprecated_var_terraform_1_10
1003+
path: tests/workflows/test-apply/deprecated_var
1004+
var: my_var=hello
1005+
var_file: tests/workflows/test-apply/test.tfvars
1006+
1007+
- name: Apply
1008+
uses: ./terraform-apply
1009+
id: apply
1010+
with:
1011+
label: test-apply deprecated_var_terraform_1_10
1012+
path: tests/workflows/test-apply/deprecated_var
1013+
var: my_var=hello
1014+
var_file: tests/workflows/test-apply/test.tfvars
1015+
1016+
- name: Check failed to apply
1017+
env:
1018+
OUTCOME: ${{ steps.apply.outcome }}
1019+
run: |
1020+
if [[ "$OUTCOME" != "failure" ]]; then
1021+
echo "Apply did not fail correctly"
1022+
exit 1
1023+
fi
1024+
9831025
apply_refresh:
9841026
runs-on: ubuntu-24.04
9851027
name: Apply changes are refresh
@@ -1474,7 +1516,7 @@ jobs:
14741516
with:
14751517
label: test-apply ephemeral 2
14761518
path: tests/workflows/test-apply/ephemeral
1477-
variables:
1519+
variables: |
14781520
region = "eu-west-1"
14791521
mv = "hello"
14801522
@@ -1484,7 +1526,7 @@ jobs:
14841526
with:
14851527
label: test-apply ephemeral 2
14861528
path: tests/workflows/test-apply/ephemeral
1487-
variables:
1529+
variables: |
14881530
region = "eu-west-1"
14891531
mv = "hello"
14901532
@@ -1504,7 +1546,7 @@ jobs:
15041546
with:
15051547
label: test-apply ephemeral 3
15061548
path: tests/workflows/test-apply/ephemeral
1507-
variables:
1549+
variables: |
15081550
region = "eu-west-2"
15091551
mv = "goodbye"
15101552
@@ -1515,7 +1557,7 @@ jobs:
15151557
with:
15161558
label: test-apply ephemeral 3
15171559
path: tests/workflows/test-apply/ephemeral
1518-
variables:
1560+
variables: |
15191561
region = "eu-west-2"
15201562
mv = "mismatch"
15211563

image/entrypoints/apply.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ function apply() {
8686
elif [[ $APPLY_EXIT -eq 0 ]]; then
8787
output
8888
update_comment apply-complete "$STEP_TMP_DIR/terraform_output.json"
89+
elif [[ "$TOOL_PRODUCT_NAME" == "Terraform" && -n "$DEPRECATED_VAR_ARGS" ]] && test-terraform-version ">=" "1.10.0" && grep -q "Error: Can't change variable"; then
90+
error_log "The deprecated 'var' input does not work with ephemeral variables in Terraform >= 1.10.0. Use the 'variables' input instead."
91+
update_comment error
92+
exit 1
8993
else
9094
if lock-info "$STEP_TMP_DIR/terraform_apply.stderr"; then
9195
set_output failure-reason state-locked

0 commit comments

Comments
 (0)