Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Terraform crash when creating an entity that already exists #899

Merged
merged 2 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions vault/resource_identity_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ func identityEntityCreate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return fmt.Errorf("error writing IdentityEntity to %q: %s", name, err)
}

if resp == nil {
path := identityEntityNamePath(name)
entityMsg := "Unable to determine entity id."

if entity, err := client.Logical().Read(path); err == nil {
entityMsg = fmt.Sprintf("Entity resource ID %q may be imported.", entity.Data["id"])
}

return fmt.Errorf("Identity Entity %q already exists. %s", name, entityMsg)
}

log.Printf("[DEBUG] Wrote IdentityEntity %q", name)

d.SetId(resp.Data["id"].(string))
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/identity_entity.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ The following arguments are supported:
## Attributes Reference

* `id` - The `id` of the created entity.

## Import

Identity entity can be imported using the `id`, e.g.

```
$ terraform import vault_identity_entity.test "ae6f8ued-0f1a-9f6b-2915-1a2be20dc053"
```