-
Notifications
You must be signed in to change notification settings - Fork 13
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `SkipIfNotAlpha` version check for testing experimental features | ||
of alpha Terraform builds.' | ||
time: 2024-11-08T16:06:34.662822-05:00 | ||
custom: | ||
Issue: "388" |
10 changes: 10 additions & 0 deletions
10
...r/resource/testdata/TestTest_ConfigDirectory_TestNameDirectory_MultipleFiles_Vars/vars.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
variable "length" { | ||
type = number | ||
} | ||
|
||
variable "numeric" { | ||
type = bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tfversion | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// SkipIfNotAlpha will skip (pass) the test if the Terraform CLI | ||
// version is not an alpha prerelease (for example, 1.10.0-alpha20241023). | ||
// | ||
// Alpha builds of Terraform include experimental features, so this version check | ||
// can be used for acceptance testing of experimental features, such as deferred actions. | ||
func SkipIfNotAlpha() TerraformVersionCheck { | ||
return skipIfNotAlphaCheck{} | ||
} | ||
|
||
// skipIfNotAlphaCheck implements the TerraformVersionCheck interface | ||
type skipIfNotAlphaCheck struct{} | ||
|
||
// CheckTerraformVersion satisfies the TerraformVersionCheck interface. | ||
func (s skipIfNotAlphaCheck) CheckTerraformVersion(ctx context.Context, req CheckTerraformVersionRequest, resp *CheckTerraformVersionResponse) { | ||
if strings.Contains(req.TerraformVersion.Prerelease(), "alpha") { | ||
return | ||
} | ||
|
||
resp.Skip = fmt.Sprintf("Terraform CLI version %s is not an alpha build: skipping test.", req.TerraformVersion) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tfversion_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
|
||
r "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
|
||
testinginterface "github.com/mitchellh/go-testing-interface" | ||
) | ||
|
||
func Test_SkipIfNotAlpha_SkipTest_Stable(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0") | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature | ||
return nil, nil | ||
}, | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func Test_SkipIfNotAlpha_SkipTest_Beta1(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-beta1") | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": providerserver.NewProviderServer(testprovider.Provider{}), | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} | ||
func Test_SkipIfNotAlpha_SkipTest_RC(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc2") | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": providerserver.NewProviderServer(testprovider.Provider{}), | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func Test_SkipIfNotAlpha_RunTest_Alpha(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.9.0-alpha20240501") | ||
|
||
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": providerserver.NewProviderServer(testprovider.Provider{}), | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
I don't think this is a bug in Terraform core necessarily, since it already warns users about this misconfiguration, for example, during plan:
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 👍🏻