Skip to content

Commit 88de250

Browse files
committed
style updates to documentation and nil checks
1 parent bcd5904 commit 88de250

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

builtin/providers/aws/resource_aws_opsworks_instance.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,19 @@ func resourceAwsOpsworksInstanceRead(d *schema.ResourceData, meta interface{}) e
510510
return err
511511
}
512512

513+
// If nothing was found, then return no state
514+
if len(resp.Instances) == 0 {
515+
d.SetId("")
516+
return nil
517+
}
513518
instance := resp.Instances[0]
519+
520+
if instance.InstanceId == nil {
521+
d.SetId("")
522+
return nil
523+
}
514524
instanceId := *instance.InstanceId
525+
515526
d.SetId(instanceId)
516527
d.Set("agent_version", instance.AgentVersion)
517528
d.Set("ami_id", instance.AmiId)
@@ -726,6 +737,10 @@ func resourceAwsOpsworksInstanceCreate(d *schema.ResourceData, meta interface{})
726737
return err
727738
}
728739

740+
if resp.InstanceId == nil {
741+
return fmt.Errorf("Error launching instance: no instance returned in response")
742+
}
743+
729744
instanceId := *resp.InstanceId
730745
d.SetId(instanceId)
731746
d.Set("id", instanceId)

website/source/docs/providers/aws/r/opsworks_instance.html.markdown

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ Provides an OpsWorks instance resource.
1313
## Example Usage
1414

1515
```
16-
resource "aws_opsworks_instance" "my-instance" {
16+
aws_opsworks_instance" "my-instance" {
1717
stack_id = "${aws_opsworks_stack.my-stack.id}"
18+
1819
layer_ids = [
1920
"${aws_opsworks_custom_layer.my-layer.id}",
2021
]
22+
2123
instance_type = "t2.micro"
22-
os = "Amazon Linux 2015.09"
23-
state = "stopped"
24+
os = "Amazon Linux 2015.09"
25+
state = "stopped"
26+
}
2427
```
2528

2629
## Argument Reference

0 commit comments

Comments
 (0)