provider/aws: Show state reason when EC2 instance fails to launch (#14479)

This commit is contained in:
Radek Simko 2017-05-15 10:31:12 +02:00 committed by GitHub
parent feb16dfdcc
commit 2964f7bc78

View File

@ -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 {