Skip to content

Commit

Permalink
provider/aws: Show state reason when EC2 instance fails to launch (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored May 15, 2017
1 parent feb16df commit 2964f7b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,29 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, instanceID string) resource.StateRe
}

i := resp.Reservations[0].Instances[0]
return i, *i.State.Name, nil
state := *i.State.Name

if state == "terminated" {
return i, state, fmt.Errorf("Failed to launch instance. Reason: %s",
stringifyStateReason(i.StateReason))

}

return i, state, nil
}
}

func stringifyStateReason(sr *ec2.StateReason) string {
if sr.Message != nil {
return *sr.Message
}
if sr.Code != nil {
return *sr.Code
}

return sr.String()
}

func readBlockDevices(d *schema.ResourceData, instance *ec2.Instance, conn *ec2.EC2) error {
ibds, err := readBlockDevicesFromInstance(instance, conn)
if err != nil {
Expand Down

0 comments on commit 2964f7b

Please sign in to comment.