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

add support for cross version provider import #778

Closed

Conversation

ms-henglu
Copy link

@ms-henglu ms-henglu commented Jul 6, 2021

This solution is used to detect SDK behavioral change when upgrade SDK for terraform providers. It takes advantage of existing acceptance tests. By deploying resources with released provider and using import step with developing provider to check whether there's a behavioral change.

Here's an example of detecting breaking change like https://azure.microsoft.com/en-us/updates/zone-behavior-change/. If there's a breaking behavioral change after SDK upgrade, running acc tests will show ImportStateVerify attributes not equivalent.


=== RUN   TestAccPublicIpStatic_standard
=== PAUSE TestAccPublicIpStatic_standard
=== CONT  TestAccPublicIpStatic_standard
    testcase.go:95: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
        
        (map[string]string) (len=4) {
         (string) (len=7) "zones.#": (string) (len=1) "3",
         (string) (len=7) "zones.0": (string) (len=1) "1",
         (string) (len=7) "zones.1": (string) (len=1) "2",
         (string) (len=7) "zones.2": (string) (len=1) "3"
        }
        
        
        (map[string]string) {
        }

And this feature is disabled by default. So it won't affect regular acceptance tests.

Similar issue: #628

This is just an idea to prevent breaking change in SDK upgrade, I'm open to all suggestions. 😃

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

@bflad
Copy link
Contributor

bflad commented Aug 26, 2022

Hi @ms-henglu 👋 Thank you for raising this awhile ago and apologies for the delayed review. We wound up resolving this in a different way over in #972 and I apologize that I had missed this existing attempt prior to submitting that.

Provider acceptance testing using v2.17.0 or later can now specify providers at either the TestCase or TestStep level.

For example:

resource.TestCase{
	Steps: []resource.TestStep{
		// Use existing provider release
		{
			Config: `resource "null_resource" "test" {}`,
			ExternalProviders: map[string]resource.ExternalProvider{
				"null": {
					Source:            "registry.terraform.io/hashicorp/null",
					VersionConstraint: "3.1.1",
				},
			},
		},
		// Use provider codebase
		{
			Config: `resource "null_resource" "test" {}`,
			ProviderFactories: map[string]func() (*schema.Provider, error){
				"null": func() (*schema.Provider, error) { /* ... */ },
			},
		},
	},
}

Hope this helps and thanks again for the submission!

@bflad bflad closed this Aug 26, 2022
@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 Sep 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants