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`.
This commit is contained in:
parent
488738163b
commit
545b8a3cd0
|
@ -132,6 +132,11 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"instance_state": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
|
||||||
"private_dns": &schema.Schema{
|
"private_dns": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
@ -449,12 +454,16 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
instance := resp.Reservations[0].Instances[0]
|
instance := resp.Reservations[0].Instances[0]
|
||||||
|
|
||||||
|
if instance.State != nil {
|
||||||
// If the instance is terminated, then it is gone
|
// If the instance is terminated, then it is gone
|
||||||
if *instance.State.Name == "terminated" {
|
if *instance.State.Name == "terminated" {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set("instance_state", instance.State.Name)
|
||||||
|
}
|
||||||
|
|
||||||
if instance.Placement != nil {
|
if instance.Placement != nil {
|
||||||
d.Set("availability_zone", instance.Placement.AvailabilityZone)
|
d.Set("availability_zone", instance.Placement.AvailabilityZone)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue