Merge pull request #9209 from hashicorp/ssm-panic-fix

builder/amazon Fix invalid pointer issue for non SSMAgengtEnabled builds
This commit is contained in:
Megan Marsh 2020-05-12 15:16:34 -07:00 committed by GitHub
commit 5b6f4a3286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -89,8 +89,18 @@ func (s *StepCreateSSMTunnel) Run(ctx context.Context, state multistep.StateBag)
// Cleanup terminates an active session on AWS, which in turn terminates the associated tunnel process running on the local machine. // Cleanup terminates an active session on AWS, which in turn terminates the associated tunnel process running on the local machine.
func (s *StepCreateSSMTunnel) Cleanup(state multistep.StateBag) { func (s *StepCreateSSMTunnel) Cleanup(state multistep.StateBag) {
if !s.SSMAgentEnabled {
return
}
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if s.session == nil || s.session.SessionId == nil {
msg := fmt.Sprintf("Unable to find a valid session to instance %q; skipping the termination step", s.instanceId)
ui.Error(msg)
return
}
ssmconn := ssm.New(s.AWSSession) ssmconn := ssm.New(s.AWSSession)
_, err := ssmconn.TerminateSession(&ssm.TerminateSessionInput{SessionId: s.session.SessionId}) _, err := ssmconn.TerminateSession(&ssm.TerminateSessionInput{SessionId: s.session.SessionId})
if err != nil { if err != nil {