Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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