terraform-plugin-sdk icon indicating copy to clipboard operation
terraform-plugin-sdk copied to clipboard

add support for cross version provider import

Open ms-henglu opened this issue 4 years ago • 1 comments

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: https://github.com/hashicorp/terraform-plugin-sdk/issues/628

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

ms-henglu avatar Jul 06 '21 06:07 ms-henglu

CLA assistant check
All committers have signed the CLA.

hashicorp-cla avatar Mar 12 '22 17:03 hashicorp-cla

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 avatar Aug 26 '22 17:08 bflad

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[bot] avatar Sep 26 '22 02:09 github-actions[bot]