Skip to content

Commit

Permalink
Fix Terraform crash when creating an entity that already exists (hash…
Browse files Browse the repository at this point in the history
…icorp#899)

* Fix nil pointer exception

* Add import details to doc
  • Loading branch information
husunal authored Nov 23, 2020
1 parent a9d0a97 commit 85eb27d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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"
```

0 comments on commit 85eb27d

Please sign in to comment.