Skip to content

Plugin SDK incorrectly states resource has no errors when Resource Identity enabled and provider sets id when create errors #1541

@gdavison

Description

@gdavison

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1

Expected Behavior

Create operation fails with expected error.

Actual Behavior

Create operation fails with expected error and Missing Resource Identity After Create: The Terraform provider unexpectedly returned no resource identity after having no errors in the resource error.

Steps to Reproduce

In resource code, set id in create that fails. (This allows a tainted resource to be saved in state to allow cleanup in a future apply)

If there is no state, the conditional at

if destroy || newInstanceState == nil || newInstanceState.Attributes == nil || newInstanceState.ID == "" {
exits without checking for Resource Identity.

However, if id is set, the return is skipped and it continues on the the Resource Identity checks at

if res.Identity != nil {
.

See, for example: hashicorp/terraform-provider-aws#45351

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions