Add more complete Read example
This commit is contained in:
parent
1cffbbb323
commit
83f29a3456
|
@ -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.
|
||||
|
||||
```go
|
||||
// Tells Terraform the resource no longer exists
|
||||
d.SetId("")
|
||||
func resourceServerRead(d *schema.ResourceData, m interface{}) error {
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue