Merge pull request #10200 from aleksandrserbin/feature/describe-instance-on-fail

amazon-ebs: log state details on change
This commit is contained in:
Megan Marsh 2020-11-20 15:31:40 -08:00 committed by GitHub
commit f4041ee4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -245,6 +245,16 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
err := fmt.Errorf("Error waiting for instance (%s) to become ready: %s", instanceId, err)
state.Put("error", err)
ui.Error(err.Error())
// try to get some context from AWS on why was instance
// transitioned to the unexpected state
if resp, e := ec2conn.DescribeInstances(describeInstance); e == nil {
if len(resp.Reservations) > 0 && len(resp.Reservations[0].Instances) > 0 {
instance := resp.Reservations[0].Instances[0]
ui.Error(fmt.Sprintf("Instance state change details: %s: %s",
*instance.StateTransitionReason, *instance.StateReason.Message))
}
}
return multistep.ActionHalt
}