-
Notifications
You must be signed in to change notification settings - Fork 232
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
helper/resource: Prevent Inconsistent dependency lock file
errors when using ExternalProviders
outside the hashicorp
namespace
#1057
Conversation
…hen using `ExternalProviders` outside the `hashicorp` namespace By default, Terraform CLI will use the `registry.terraform.io` hostname and `hashicorp` namespace for provider addresses if there is not a `terraform` configuration block with an explicit configuration. Previously, the testing framework would automatically generate a temporary configuration with the `terraform` configuration block for running `terraform init`, but it did not include this extra configuration along with a given `TestStep` `Config`. When working with `hashicorp` namespace providers, this isn't an issue because of the Terraform CLI defaults. External provider developers could manually workaround this issue by including the `terraform` configuration block as part of their `TestStep` `Config`, however this is certainly confusing and error prone. Previously before code adjustments: ``` === CONT TestTest_TestCase_ExternalProviders_NonHashiCorpNamespace testcase_providers_test.go:236: Step 1/1 error: Error running pre-apply refresh: Error: Inconsistent dependency lock file The following dependency selections recorded in the lock file are inconsistent with the current configuration: - provider registry.terraform.io/hashicorp/scaffoldingtest: required by this configuration but no version is selected To update the locked dependency selections to match a changed configuration, run: terraform init -upgrade --- FAIL: TestTest_TestCase_ExternalProviders_NonHashiCorpNamespace (1.91s) === CONT TestTest_TestCase_ExternalProvidersAndProviderFactories_NonHashiCorpNamespace testcase_providers_test.go:258: Step 1/1 error: Error running pre-apply refresh: Error: Inconsistent dependency lock file The following dependency selections recorded in the lock file are inconsistent with the current configuration: - provider registry.terraform.io/hashicorp/scaffoldingtest: required by this configuration but no version is selected To update the locked dependency selections to match a changed configuration, run: terraform init -upgrade --- FAIL: TestTest_TestCase_ExternalProvidersAndProviderFactories_NonHashiCorpNamespace (0.46s) === CONT TestTest_TestStep_ExternalProviders_NonHashiCorpNamespace teststep_providers_test.go:304: Step 1/1 error: Error running pre-apply refresh: Error: Inconsistent dependency lock file The following dependency selections recorded in the lock file are inconsistent with the current configuration: - provider registry.terraform.io/hashicorp/scaffoldingtest: required by this configuration but no version is selected To update the locked dependency selections to match a changed configuration, run: terraform init -upgrade --- FAIL: TestTest_TestStep_ExternalProviders_NonHashiCorpNamespace (0.32s) === CONT TestTest_TestStep_ExternalProvidersAndProviderFactories_NonHashiCorpNamespace teststep_providers_test.go:325: Step 1/1 error: Error running pre-apply refresh: Error: Inconsistent dependency lock file The following dependency selections recorded in the lock file are inconsistent with the current configuration: - provider registry.terraform.io/hashicorp/scaffoldingtest: required by this configuration but no version is selected To update the locked dependency selections to match a changed configuration, run: terraform init -upgrade --- FAIL: TestTest_TestStep_ExternalProvidersAndProviderFactories_NonHashiCorpNamespace (0.35s) ```
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.
Nice. LGTM
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Reference: https://discuss.hashicorp.com/t/acceptance-testing-sdk-framework-upgrade-issue/44166
Reference: https://www.terraform.io/plugin/framework/migrating/testing
By default, Terraform CLI will use the
registry.terraform.io
hostname andhashicorp
namespace for provider addresses if there is not aterraform
configuration block with an explicit configuration. Previously, the testing framework would automatically generate a temporary configuration with theterraform
configuration block for runningterraform init
, but it did not include this extra configuration along with a givenTestStep
Config
. When working withhashicorp
namespace providers, this isn't an issue because of the Terraform CLI defaults.External provider developers could manually workaround this issue by including the
terraform
configuration block as part of theirTestStep
Config
, however this is certainly confusing and error prone.This issue is especially pertinent now as the sdk/v2 to framework migration guide shows acceptance testing which uses
ExternalProviders
extensively for proving successful migrations without plan differences.Previously before code adjustments: