Skip to content

resourceSetRegionInStateInterceptor prevents proper resource removal detection for Framework resources #43655

@marcinbelczewski

Description

@marcinbelczewski

Terraform and AWS Provider Version

Terraform v1.11.0
on darwin_arm64

Affected Resource(s) or Data Source(s)

All resources using Terraform Plugin Framework that have region attributes

Expected Behavior

When a resource is deleted outside of Terraform (resource disappears), the next terraform plan should detect the resource as missing and propose to recreate it with action [create].

Actual Behavior

When a resource is deleted outside of Terraform, the resource appears to still exist in state with null values instead of being properly detected as missing. This causes incorrect plan actions showing [destroy, create] instead of just [create].

Relevant Error/Panic Output

Sample Terraform Configuration

Click to expand configuration
resource "aws_s3tables_namespace" "example" {
  namespace        = "example_namespace"
  table_bucket_arn = aws_s3tables_table_bucket.example.arn
}

resource "aws_s3tables_table_bucket" "example" {
  name = "example-bucket"
}
func TestAccS3TablesTable_disappears(t *testing.T) {
	ctx := acctest.Context(t)

	var table s3tables.GetTableOutput
	bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
	namespace := strings.ReplaceAll(sdkacctest.RandomWithPrefix(acctest.ResourcePrefix), "-", "_")
	rName := strings.ReplaceAll(sdkacctest.RandomWithPrefix(acctest.ResourcePrefix), "-", "_")
	resourceName := "aws_s3tables_table.test"

	resource.ParallelTest(t, resource.TestCase{
		PreCheck: func() {
			acctest.PreCheck(ctx, t)
			testAccPreCheck(ctx, t)
		},
		ErrorCheck:               acctest.ErrorCheck(t, names.S3TablesServiceID),
		ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
		CheckDestroy:             testAccCheckTableDestroy(ctx),
		Steps: []resource.TestStep{
			{
				Config: testAccTableConfig_basic(rName, namespace, bucketName),
				Check: resource.ComposeAggregateTestCheckFunc(
					testAccCheckTableExists(ctx, resourceName, &table),
					acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfs3tables.NewResourceTable, resourceName),
				),
				ExpectNonEmptyPlan: true,
				// Add this recommended plan check to trigger the error
				ConfigPlanChecks: resource.ConfigPlanChecks{
					PostApplyPostRefresh: []plancheck.PlanCheck{
						plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
					},
				},				
			},
		},
	})
}

Steps to Reproduce

  1. Amend TestAccS3TablesTable_disappears acceptance test enabling the recommended plancheck.ResourceActionCreate
  2. Run the test
  3. Observe failed test:

=== RUN TestAccS3TablesTable_disappears
=== PAUSE TestAccS3TablesTable_disappears
=== CONT TestAccS3TablesTable_disappears
table_test.go:116: Step 1/1 error: Post-apply refresh plan check(s) failed:
'aws_s3tables_table.test' - expected Create, got action(s): [delete create]
--- FAIL: TestAccS3TablesTable_disappears (26.54s)

Debug Logging

No response

GenAI / LLM Assisted Development

  • claude code
  • Chat GPT o3

not super helpful tbh ;-)

Important Facts and References

No response

Would you like to implement a fix?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.providerPertains to the provider itself, rather than any interaction with AWS.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions