diff --git a/pkg/destroy/aws.go b/pkg/destroy/aws.go index 0d92b6172ee..6d031f200fa 100644 --- a/pkg/destroy/aws.go +++ b/pkg/destroy/aws.go @@ -1,6 +1,7 @@ package destroy import ( + session "github.com/openshift/installer/pkg/asset/installconfig/aws" "github.com/openshift/installer/pkg/destroy/aws" "github.com/openshift/installer/pkg/types" "github.com/sirupsen/logrus" @@ -13,11 +14,17 @@ func NewAWS(logger logrus.FieldLogger, metadata *types.ClusterMetadata) (Destroy filters = append(filters, filter) } + awsSession, err := session.GetSession() + if err != nil { + return nil, err + } + return &aws.ClusterUninstaller{ Filters: filters, Region: metadata.ClusterPlatformMetadata.AWS.Region, Logger: logger, ClusterID: metadata.InfraID, + Session: awsSession, }, nil } diff --git a/pkg/destroy/aws/aws.go b/pkg/destroy/aws/aws.go index 1aca4fce33e..f1898cce1f1 100644 --- a/pkg/destroy/aws/aws.go +++ b/pkg/destroy/aws/aws.go @@ -56,6 +56,11 @@ type ClusterUninstaller struct { Logger logrus.FieldLogger Region string ClusterID string + + // Session is the AWS session to be used for deletion. If nil, a + // new session will be created based on the usual credential + // configuration (AWS_PROFILE, AWS_ACCESS_KEY_ID, etc.). + Session *session.Session } func (o *ClusterUninstaller) validate() error { @@ -73,11 +78,15 @@ func (o *ClusterUninstaller) Run() error { } awsConfig := &aws.Config{Region: aws.String(o.Region)} - - // Relying on appropriate AWS ENV vars (eg AWS_PROFILE, AWS_ACCESS_KEY_ID, etc) - awsSession, err := session.NewSession(awsConfig) - if err != nil { - return err + awsSession := o.Session + if awsSession == nil { + // Relying on appropriate AWS ENV vars (eg AWS_PROFILE, AWS_ACCESS_KEY_ID, etc) + awsSession, err = session.NewSession(awsConfig) + if err != nil { + return err + } + } else { + awsSession = awsSession.Copy(awsConfig) } awsSession.Handlers.Build.PushBackNamed(request.NamedHandler{ Name: "openshiftInstaller.OpenshiftInstallerUserAgentHandler",