mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: Show state reason when EC2 instance fails to launch (#14479)
This commit is contained in:
parent
feb16dfdcc
commit
2964f7bc78
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user