From 88de250615972584cdc480371b1a613d22a52c0e Mon Sep 17 00:00:00 2001 From: Jeff Tang Date: Thu, 24 Mar 2016 08:08:01 -0400 Subject: [PATCH] style updates to documentation and nil checks --- .../aws/resource_aws_opsworks_instance.go | 15 +++++++++++++++ .../aws/r/opsworks_instance.html.markdown | 9 ++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_opsworks_instance.go b/builtin/providers/aws/resource_aws_opsworks_instance.go index dc4051f014..bf1dbfdf30 100644 --- a/builtin/providers/aws/resource_aws_opsworks_instance.go +++ b/builtin/providers/aws/resource_aws_opsworks_instance.go @@ -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) diff --git a/website/source/docs/providers/aws/r/opsworks_instance.html.markdown b/website/source/docs/providers/aws/r/opsworks_instance.html.markdown index 20b03c2dc6..c855d559f2 100644 --- a/website/source/docs/providers/aws/r/opsworks_instance.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_instance.html.markdown @@ -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" + os = "Amazon Linux 2015.09" + state = "stopped" +} ``` ## Argument Reference