Skip to content

When importing a non-existing user, Terraform reports "This is generally a bug in the resource implementation for import" #210

@maxmansonkiv

Description

@maxmansonkiv

When importing a non-existing user, Terraform reports: Error: The provider returned a resource missing an identifier during ImportResourceState. This is generally a bug in the resource implementation for import. Resource import code should not call d.SetId("") or create an empty ResourceData. If the resource is missing, instead return an error. Please report this to the provider developers.

To reproduce this error, run terraform import as follows:

terraform import mysql_user.testuser222 testuser222@%

Also, create a .tf file pointing to a valid Mysql provider:

resource "mysql_user" "testuser222" {
  provider = mysql.mydatabaseprovider
}

Make sure the user testuser222 doesn't actually exist in the database.

To fix this error, the function ImportUser should include better error handling of value returned by the function ReadUser and in case of a user is not found, report an error rather then returning an empty resource data. The function ReadUser may need to be improved as well. See

err := ReadUser(ctx, d, meta)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions