diff --git a/internal/pkg/cli/env_init.go b/internal/pkg/cli/env_init.go index 78f6394c193..f317c41cafc 100644 --- a/internal/pkg/cli/env_init.go +++ b/internal/pkg/cli/env_init.go @@ -159,23 +159,23 @@ type initEnvOpts struct { initEnvVars // Interfaces to interact with dependencies. - sessProvider sessionProvider - store store - envDeployer deployer - appDeployer deployer - identity identityService - envIdentity identityService - ec2Client ec2Client - appVersionGetter versionGetter - iam roleManager - cfn stackExistChecker - prog progress - prompt prompter - selVPC ec2Selector - selCreds func() (credsSelector, error) - selApp appSelector - appCFN appResourcesGetter - manifestWriter environmentManifestWriter + sessProvider sessionProvider + store store + envDeployer deployer + appDeployer deployer + identity identityService + envIdentity identityService + ec2Client ec2Client + newAppVersionGetter func(appName string) (versionGetter, error) + iam roleManager + cfn stackExistChecker + prog progress + prompt prompter + selVPC ec2Selector + selCreds func() (credsSelector, error) + selApp appSelector + appCFN appResourcesGetter + manifestWriter environmentManifestWriter sess *session.Session // Session pointing to environment's AWS account and region. @@ -218,6 +218,9 @@ func newInitEnvOpts(vars initEnvVars) (*initEnvOpts, error) { Prompt: prompt.New(), }, nil }, + newAppVersionGetter: func(appName string) (versionGetter, error) { + return describe.NewAppDescriber(appName) + }, selApp: selector.NewAppEnvSelector(prompt.New(), store), appCFN: deploycfn.New(defaultSession, deploycfn.WithProgressTracker(os.Stderr)), manifestWriter: ws, @@ -269,7 +272,11 @@ func (o *initEnvOpts) Execute() error { return err } if !o.allowAppDowngrade { - if err := validateAppVersion(o.appVersionGetter, o.appName, o.templateVersion); err != nil { + versionGetter, err := o.newAppVersionGetter(o.appName) + if err != nil { + return err + } + if err := validateAppVersion(versionGetter, o.appName, o.templateVersion); err != nil { return err } } @@ -354,13 +361,6 @@ func (o *initEnvOpts) initRuntimeClients() error { if o.iam == nil { o.iam = iam.New(o.sess) } - if o.appVersionGetter == nil { - appDescriber, err := describe.NewAppDescriber(o.appName) - if err != nil { - return err - } - o.appVersionGetter = appDescriber - } return nil } diff --git a/internal/pkg/cli/env_init_test.go b/internal/pkg/cli/env_init_test.go index 5401c05677a..34b4812d19e 100644 --- a/internal/pkg/cli/env_init_test.go +++ b/internal/pkg/cli/env_init_test.go @@ -1283,19 +1283,21 @@ func TestInitEnvOpts_Execute(t *testing.T) { }, allowAppDowngrade: tc.allowDowngrade, }, - store: m.store, - envDeployer: m.deployer, - appDeployer: m.deployer, - identity: m.identity, - envIdentity: m.identity, - iam: m.iam, - cfn: m.cfn, - prog: m.progress, - sess: sess, - appCFN: m.appCFN, - appVersionGetter: m.appVersionGetter, - manifestWriter: m.manifestWriter, - templateVersion: mockCurrVersion, + store: m.store, + envDeployer: m.deployer, + appDeployer: m.deployer, + identity: m.identity, + envIdentity: m.identity, + iam: m.iam, + cfn: m.cfn, + prog: m.progress, + sess: sess, + appCFN: m.appCFN, + newAppVersionGetter: func(appName string) (versionGetter, error) { + return m.appVersionGetter, nil + }, + manifestWriter: m.manifestWriter, + templateVersion: mockCurrVersion, } // WHEN diff --git a/internal/pkg/cli/init.go b/internal/pkg/cli/init.go index ceb53ed0a9a..c6e44e0b7f1 100644 --- a/internal/pkg/cli/init.go +++ b/internal/pkg/cli/init.go @@ -114,10 +114,6 @@ func newInitOpts(vars initVars) (*initOpts, error) { id := identity.New(defaultSess) deployer := cloudformation.New(defaultSess, cloudformation.WithProgressTracker(os.Stderr)) iamClient := iam.New(defaultSess) - appVersionGetter, err := describe.NewAppDescriber(vars.appName) - if err != nil { - return nil, err - } initAppCmd := &initAppOpts{ initAppVars: initAppVars{ name: vars.appName, @@ -141,24 +137,24 @@ func newInitOpts(vars initVars) (*initOpts, error) { } initEnvCmd := &initEnvOpts{ initEnvVars: initEnvVars{ - appName: vars.appName, name: defaultEnvironmentName, isProduction: false, }, - store: configStore, - appDeployer: deployer, - prog: spin, - prompt: prompt, - identity: id, - appVersionGetter: appVersionGetter, - appCFN: cloudformation.New(defaultSess, cloudformation.WithProgressTracker(os.Stderr)), - sess: defaultSess, - templateVersion: version.LatestTemplateVersion(), + store: configStore, + appDeployer: deployer, + prog: spin, + prompt: prompt, + identity: id, + newAppVersionGetter: func(appName string) (versionGetter, error) { + return describe.NewAppDescriber(appName) + }, + appCFN: cloudformation.New(defaultSess, cloudformation.WithProgressTracker(os.Stderr)), + sess: defaultSess, + templateVersion: version.LatestTemplateVersion(), } deployEnvCmd := &deployEnvOpts{ deployEnvVars: deployEnvVars{ - appName: vars.appName, - name: defaultEnvironmentName, + name: defaultEnvironmentName, }, store: configStore, sessionProvider: sessProvider, @@ -178,7 +174,6 @@ func newInitOpts(vars initVars) (*initOpts, error) { deployWkldVars: deployWkldVars{ envName: defaultEnvironmentName, imageTag: vars.imageTag, - appName: vars.appName, }, store: configStore, @@ -197,7 +192,6 @@ func newInitOpts(vars initVars) (*initOpts, error) { deployWkldVars: deployWkldVars{ envName: defaultEnvironmentName, imageTag: vars.imageTag, - appName: vars.appName, }, store: configStore, newInterpolator: newManifestInterpolator,