Acceptance testing: Detect update in place vs. Delete+Create

I’d like to validate my provider’s “requires replace” logic in my acceptance testing.

I’m using github.com/hashicorp/terraform-plugin-testing/helper/resource.

The first resource.TestStep within a resource.TestCase will always cause my Create() method to be executed… But how can I detect whether the second resource.TestStep leads to Update() or Delete() plus Create()?

I’d like to ensure both conditions:

  1. Some configuration sequences guarantee recreation
  2. Other configuration sequences guarantee update-in-place

Thanks!

Hey @hQnVyLRx :wave: ,

You can assert the action planned for a resource, probably best to go in a ConfigPlanChecks.PreApply plan check with plancheck.ExpectResourceAction, for example: terraform-provider-aws/internal/service/dms/replication_task_test.go at 0c9edd45ad5b079fe7186bf8ac957371a964811c · hashicorp/terraform-provider-aws · GitHub.

You can see all the available action types to assert in our package docs: plancheck package - github.com/hashicorp/terraform-plugin-testing/plancheck - Go Packages

(edit: fixed link :slightly_smiling_face:)

Thank you, @austin.valle!

That’s exactly what I was looking for.

Side note, the GitHub link may be to a private repo, but this seems to be the public version of the same code.