-
Notifications
You must be signed in to change notification settings - Fork 10.1k
PSS: Add reusable method for obtaining the provider factory needed for accessing a state store. #37665
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
Merged
Merged
PSS: Add reusable method for obtaining the provider factory needed for accessing a state store. #37665
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e71dd66
Add method to allow accessing factories from locks that are in memory
SarahFrench 1c93449
Create new getStateStoreProviderFactory method for accessing a factor…
SarahFrench 80c618c
Update getStateStoreProviderFactory to use in memory locks instead of…
SarahFrench 335ae39
Add tests for getStateStoreProviderFactory, improve errors returned f…
SarahFrench 86a1065
Update test following schema change in simple providers
SarahFrench a6e348a
Move test case into e2etest package, so we protect against environmen…
SarahFrench 65007d3
Fix issues with running test in e2etest package
SarahFrench 37ea0ea
Update code comments
SarahFrench 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 hidden or 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,85 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| package e2etest | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/apparentlymart/go-versions/versions" | ||
| tfaddr "github.com/hashicorp/terraform-registry-address" | ||
| "github.com/hashicorp/terraform/internal/addrs" | ||
| "github.com/hashicorp/terraform/internal/command" | ||
| "github.com/hashicorp/terraform/internal/configs" | ||
| "github.com/hashicorp/terraform/internal/depsfile" | ||
| "github.com/hashicorp/terraform/internal/e2e" | ||
| "github.com/hashicorp/terraform/internal/getproviders" | ||
| "github.com/hashicorp/terraform/internal/getproviders/providerreqs" | ||
| ) | ||
|
|
||
| func TestMetaBackend_GetStateStoreProviderFactory(t *testing.T) { | ||
| t.Run("gets the matching factory from local provider cache", func(t *testing.T) { | ||
| if !canRunGoBuild { | ||
| // We're running in a separate-build-then-run context, so we can't | ||
| // currently execute this test which depends on being able to build | ||
| // new executable at runtime. | ||
| // | ||
| // (See the comment on canRunGoBuild's declaration for more information.) | ||
| t.Skip("can't run without building a new provider executable") | ||
| } | ||
|
|
||
| // Set up locks | ||
| locks := depsfile.NewLocks() | ||
| providerAddr := addrs.MustParseProviderSourceString("registry.terraform.io/hashicorp/simple") | ||
| constraint, err := providerreqs.ParseVersionConstraints(">1.0.0") | ||
| if err != nil { | ||
| t.Fatalf("test setup failed when making constraint: %s", err) | ||
| } | ||
| locks.SetProvider( | ||
| providerAddr, | ||
| versions.MustParseVersion("9.9.9"), | ||
| constraint, | ||
| []providerreqs.Hash{""}, | ||
| ) | ||
|
|
||
| // Set up a local provider cache for the test to use | ||
| // 1. Build a binary for the current platform | ||
| simple6Provider := filepath.Join(".", "terraform-provider-simple6") | ||
| simple6ProviderExe := e2e.GoBuild("github.com/hashicorp/terraform/internal/provider-simple-v6/main", simple6Provider) | ||
| // 2. Create a working directory with .terraform/providers directory | ||
| td := t.TempDir() | ||
| t.Chdir(td) | ||
| providerPath := fmt.Sprintf(".terraform/providers/registry.terraform.io/hashicorp/simple/9.9.9/%s", getproviders.CurrentPlatform.String()) | ||
| err = os.MkdirAll(providerPath, os.ModePerm) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| // 3. Move the binary into the cache folder created above. | ||
| os.Rename(simple6ProviderExe, fmt.Sprintf("%s/%s/terraform-provider-simple", td, providerPath)) | ||
|
|
||
| config := &configs.StateStore{ | ||
| ProviderAddr: tfaddr.MustParseProviderSource("registry.terraform.io/hashicorp/simple"), | ||
| // No other fields necessary for test. | ||
| } | ||
|
|
||
| // Setup the meta and test providerFactoriesDuringInit | ||
| m := command.Meta{} | ||
| factory, diags := m.GetStateStoreProviderFactory(config, locks) | ||
| if diags.HasErrors() { | ||
| t.Fatalf("unexpected error : %s", err) | ||
| } | ||
|
|
||
| p, _ := factory() | ||
| defer p.Close() | ||
| s := p.GetProviderSchema() | ||
| expectedProviderDescription := "This is terraform-provider-simple v6" | ||
| if s.Provider.Body.Description != expectedProviderDescription { | ||
| t.Fatalf("expected description to be %q, but got %q", expectedProviderDescription, s.Provider.Body.Description) | ||
| } | ||
|
Comment on lines
+78
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the reason for adding descriptions to the simple providers' schemas |
||
| }) | ||
|
|
||
| // See command/meta_backend_test.go for other test cases | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.