From 545b8a3cd0b731e60137bbb1f8735ec621a01ce0 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Thu, 17 Sep 2015 13:26:38 +0300 Subject: [PATCH] aws: store and read instance state This allows us to store the instance state into the state file. This means we can now easily see the instance state with `terraform show`. --- builtin/providers/aws/resource_aws_instance.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index 093b6ae86..6752f8e69 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -132,6 +132,11 @@ func resourceAwsInstance() *schema.Resource { Computed: true, }, + "instance_state": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "private_dns": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -449,10 +454,14 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error { instance := resp.Reservations[0].Instances[0] - // If the instance is terminated, then it is gone - if *instance.State.Name == "terminated" { - d.SetId("") - return nil + if instance.State != nil { + // If the instance is terminated, then it is gone + if *instance.State.Name == "terminated" { + d.SetId("") + return nil + } + + d.Set("instance_state", instance.State.Name) } if instance.Placement != nil {