diff --git a/builtin/providers/aws/resource_aws_opsworks_instance.go b/builtin/providers/aws/resource_aws_opsworks_instance.go index dc4051f01..bf1dbfdf3 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 20b03c2dc..c855d559f 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