Add more complete Read example

This commit is contained in:
Seth Vargo 2017-05-05 17:36:30 -04:00
parent 1cffbbb323
commit 83f29a3456
No known key found for this signature in database
GPG Key ID: C921994F9C27E0FF
1 changed files with 16 additions and 2 deletions

View File

@ -545,8 +545,22 @@ exists (maybe it was destroyed out of band). Just like the destroy callback, the
`Read` function should gracefully handle this case. `Read` function should gracefully handle this case.
```go ```go
// Tells Terraform the resource no longer exists func resourceServerRead(d *schema.ResourceData, m interface{}) error {
d.SetId("") client := meta.(*MyClient)
// Attempt to read from an upstream API
obj, ok := client.Get(d.Id())
// If the resource does not exist, inform Terraform. We want to immediately
// return here to prevent further processing.
if !ok {
d.SetId("")
return nil
}
d.Set("address", obj.Address)
return nil
}
``` ```
## Next Steps ## Next Steps