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

helper/resource: Prevent Inconsistent dependency lock file errors when using ExternalProviders outside the hashicorp namespace #1057

Merged
merged 2 commits into from
Sep 14, 2022

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Sep 14, 2022

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 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.

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:

=== 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)

…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)
```
@bflad bflad added bug Something isn't working subsystem/tests Issues and feature requests related to the testing framework. labels Sep 14, 2022
@bflad bflad added this to the v2.23.0 milestone Sep 14, 2022
@bflad bflad requested a review from a team as a code owner September 14, 2022 01:09
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

Nice. LGTM

@bflad bflad merged commit ef65fde into main Sep 14, 2022
@bflad bflad deleted the bflad/ExternalProviders-always-be-prepending branch September 14, 2022 13:09
@github-actions
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working subsystem/tests Issues and feature requests related to the testing framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants