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

tfversion: Add SkipIfNotAlpha version check #388

Merged
merged 3 commits into from
Nov 15, 2024
Merged

Conversation

austinvalle
Copy link
Member

Since we've recently added beta prereleases to our acceptance testing, we started getting test failures for experimental features like deferred actions that use the SkipIfNotPrerelease version check. That's because the only prerelease builds that get experimental features (like deferred actions) are alpha and source builds.

None of our CI uses source builds, so I just created a new SkipIfNotAlpha version check we can use for experimental features, while allowing beta builds to run in our CI successfully 👍🏻

@austinvalle austinvalle added the enhancement New feature or request label Nov 8, 2024
@austinvalle austinvalle added this to the v1.11.0 milestone Nov 8, 2024
@austinvalle austinvalle requested a review from a team as a code owner November 8, 2024 21:02
@austinvalle
Copy link
Member Author

You can see some example test failures in our recent dependabot PRs when it fails to skip properly for 1.10.0-beta1: https://github.com/hashicorp/terraform-plugin-testing/actions/runs/11742344241/job/32712881987?pr=387

--- FAIL: Test_ExpectDeferredChange_Reason_Match (0.51s)
    expect_deferred_change_test.go:24: Step 1/1 error: Error running pre-apply plan: -allow-deferral is only
available in experimental Terraform builds: experiments are not enabled in version 1.10.0-beta1, as it's not
an alpha or dev build

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updating our CI to Terraform 1.10.0-rc1, I found an invalid test setup due to a new error from the introduction of ephemeral variables in the apply command, which rejects variables not defined in configuration during apply.

Example (names are different because I was testing it locally)

│ Error: Can't set variable when applying a saved plan

│   on test.auto.tfvars.json line 3:
│    3:     "var_two": false

│ The variable var_two cannot be set using the -var and -var-file options when applying a saved plan file, because it is neither ephemeral nor has it been declared during the plan operation.
│ To declare an ephemeral variable which is not saved in the plan file, use ephemeral = true.

I don't think this is a bug in Terraform core necessarily, since it already warns users about this misconfiguration, for example, during plan:

│ Error: Can't set variable when applying a saved plan

│   on test.auto.tfvars.json line 3:
│    3:     "var_two": false

│ The variable var_two cannot be set using the -var and -var-file options when applying a saved plan file, because it is neither ephemeral nor has it been declared during the plan operation.
│ To declare an ephemeral variable which is not saved in the plan file, use ephemeral = true.

I think in our case here, the test was simply not setup properly, and the new version of Terraform is confirming that. So the fix here is just correctly declaring the variables in the configuration 👍🏻

@austinvalle austinvalle merged commit 918aea6 into main Nov 15, 2024
36 checks passed
@austinvalle austinvalle deleted the av/skip-if-not-alpha branch November 15, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants