Skip to content

Error with state upgrades after terraform-plugin-testing@v1.6.0 update #237

Closed as not planned
@ewbankkit

Description

@ewbankkit

terraform-plugin-testing version

v1.6.0

Relevant provider source code

Terraform Schema
		resourceV0 := &schema.Resource{Schema: map[string]*schema.Schema{}}

		SchemaVersion: 1,
		StateUpgraders: []schema.StateUpgrader{
			{
				Type: resourceV0.CoreConfigSchema().ImpliedType(),
				Upgrade: func(_ context.Context, rawState map[string]interface{}, _ interface{}) (map[string]interface{}, error) {
					if v, ok := rawState["enable_default_standards"]; !ok || v == nil {
						rawState["enable_default_standards"] = "true"
					}

					return rawState, nil
				},
				Version: 0,
			},
		},
		Schema: map[string]*schema.Schema{
			"enable_default_standards": {
				Type:     schema.TypeBool,
				Optional: true,
				ForceNew: true,
				Default:  true,
			},
		},
Acceptance Test Case
func testAccAccount_migrateV0(t *testing.T) {
	ctx := acctest.Context(t)
	resourceName := "aws_securityhub_account.test"

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { acctest.PreCheck(ctx, t) },
		ErrorCheck:   acctest.ErrorCheck(t, names.SecurityHubEndpointID),
		CheckDestroy: testAccCheckAccountDestroy(ctx),
		Steps: []resource.TestStep{
			{
				ExternalProviders: map[string]resource.ExternalProvider{
					"aws": {
						Source:            "hashicorp/aws",
						VersionConstraint: "4.59.0",
					},
				},
				Config: testAccAccountConfig_basic,
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAccountExists(ctx, resourceName),
					resource.TestCheckNoResourceAttr(resourceName, "enable_default_standards"),
				),
			},
			{
				ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
				Config:                   testAccAccountConfig_basic,
				PlanOnly:                 true,
			},
		},
	})
}

Terraform Configuration Files

resource "aws_securityhub_account" "test" {}

Expected Behavior

With v1.5.1

% make testacc TESTARGS='-run=TestAccSecurityHub_serial/^Account$$/MigrateV0' PKG=securityhub
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/securityhub/... -v -count 1 -parallel 20  -run=TestAccSecurityHub_serial/^Account$/MigrateV0 -timeout 360m
=== RUN   TestAccSecurityHub_serial
=== PAUSE TestAccSecurityHub_serial
=== CONT  TestAccSecurityHub_serial
=== RUN   TestAccSecurityHub_serial/Account
=== RUN   TestAccSecurityHub_serial/Account/MigrateV0
--- PASS: TestAccSecurityHub_serial (66.17s)
    --- PASS: TestAccSecurityHub_serial/Account (66.17s)
        --- PASS: TestAccSecurityHub_serial/Account/MigrateV0 (66.17s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/securityhub	71.328s

Actual Behavior

With v1.6.0

% make testacc TESTARGS='-run=TestAccSecurityHub_serial/^Account$$/MigrateV0' PKG=securityhub
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/securityhub/... -v -count 1 -parallel 20  -run=TestAccSecurityHub_serial/^Account$/MigrateV0 -timeout 360m
=== RUN   TestAccSecurityHub_serial
=== PAUSE TestAccSecurityHub_serial
=== CONT  TestAccSecurityHub_serial
=== RUN   TestAccSecurityHub_serial/Account
=== RUN   TestAccSecurityHub_serial/Account/MigrateV0
    account_test.go:132: Step 2/2 error: After applying this test step, the plan was not empty.
        stdout:
        
        
        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
          ~ update in-place
        
        Terraform will perform the following actions:
        
          # aws_securityhub_account.test will be updated in-place
          ~ resource "aws_securityhub_account" "test" {
              + auto_enable_controls     = true
                id                       = "346386234494"
                # (1 unchanged attribute hidden)
            }
        
        Plan: 0 to add, 1 to change, 0 to destroy.
    testing_new.go:80: Error retrieving state, there may be dangling resources: exit status 1
        Failed to marshal state to json: schema version 0 for aws_securityhub_account.test in state does not match version 1 from the provider
--- FAIL: TestAccSecurityHub_serial (45.22s)
    --- FAIL: TestAccSecurityHub_serial/Account (45.22s)
        --- FAIL: TestAccSecurityHub_serial/Account/MigrateV0 (45.22s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/securityhub	51.015s
FAIL
make: *** [testacc] Error 1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions