style updates to documentation and nil checks

This commit is contained in:
Jeff Tang 2016-03-24 08:08:01 -04:00
parent bcd5904eea
commit 88de250615
2 changed files with 21 additions and 3 deletions

View File

@ -510,8 +510,19 @@ func resourceAwsOpsworksInstanceRead(d *schema.ResourceData, meta interface{}) e
return err
}
// If nothing was found, then return no state
if len(resp.Instances) == 0 {
d.SetId("")
return nil
}
instance := resp.Instances[0]
if instance.InstanceId == nil {
d.SetId("")
return nil
}
instanceId := *instance.InstanceId
d.SetId(instanceId)
d.Set("agent_version", instance.AgentVersion)
d.Set("ami_id", instance.AmiId)
@ -726,6 +737,10 @@ func resourceAwsOpsworksInstanceCreate(d *schema.ResourceData, meta interface{})
return err
}
if resp.InstanceId == nil {
return fmt.Errorf("Error launching instance: no instance returned in response")
}
instanceId := *resp.InstanceId
d.SetId(instanceId)
d.Set("id", instanceId)

View File

@ -13,14 +13,17 @@ Provides an OpsWorks instance resource.
## Example Usage
```
resource "aws_opsworks_instance" "my-instance" {
aws_opsworks_instance" "my-instance" {
stack_id = "${aws_opsworks_stack.my-stack.id}"
layer_ids = [
"${aws_opsworks_custom_layer.my-layer.id}",
]
instance_type = "t2.micro"
os = "Amazon Linux 2015.09"
state = "stopped"
}
```
## Argument Reference