diff --git a/internal/pkg/cli/env_init.go b/internal/pkg/cli/env_init.go index 962b86d3484..d310823bef6 100644 --- a/internal/pkg/cli/env_init.go +++ b/internal/pkg/cli/env_init.go @@ -72,10 +72,10 @@ https://github.com/aws/copilot-cli/wiki/credentials#environment-credentials` var ( errNamedProfilesNotFound = fmt.Errorf("no named AWS profiles found, run %s first please", color.HighlightCode("aws configure")) - envInitImportEnvResourcesSelectOption = "No, I'd like to import existing resources (VPC, subnets)." - envInitAdjustEnvResourcesSelectOption = "Yes, but I'd like configure the default resources (CIDR ranges)." - envInitWithNoCustomizedResourcesSelectOption = "Yes, use default." - envInitCustomizedEnvTypes = []string{envInitImportEnvResourcesSelectOption, envInitAdjustEnvResourcesSelectOption, envInitWithNoCustomizedResourcesSelectOption} + envInitDefaultConfigSelectOption = "Yes, use default." + envInitAdjustEnvResourcesSelectOption = "Yes, but I'd like configure the default resources (CIDR ranges)." + envInitImportEnvResourcesSelectOption = "No, I'd like to import existing resources (VPC, subnets)." + envInitCustomizedEnvTypes = []string{envInitDefaultConfigSelectOption, envInitAdjustEnvResourcesSelectOption, envInitImportEnvResourcesSelectOption} ) type importVPCVars struct { @@ -116,10 +116,10 @@ func (v tempCredsVars) isSet() bool { type initEnvVars struct { *GlobalOpts - Name string // Name for the environment. - Profile string // The named profile to use for credential retrieval. Mutually exclusive with TempCreds. - IsProduction bool // True means retain resources even after deletion. - NoCustomResources bool // True means no importing an existing VPC or adjusting a VPC. + Name string // Name for the environment. + Profile string // The named profile to use for credential retrieval. Mutually exclusive with TempCreds. + IsProduction bool // True means retain resources even after deletion. + DefaultConfig bool // True means using default environment configuration. ImportVPC importVPCVars // Existing VPC resources to use instead of creating new ones. AdjustVPC adjustVPCVars // Configure parameters for VPC resources generated while initializing an environment. @@ -261,8 +261,8 @@ func (o *initEnvOpts) validateCustomizedResources() error { if o.ImportVPC.isSet() && o.AdjustVPC.isSet() { return errors.New("cannot specify both import vpc flags and configure vpc flags") } - if (o.ImportVPC.isSet() || o.AdjustVPC.isSet()) && o.NoCustomResources { - return fmt.Errorf("cannot import or configure vpc if --%s is set", noCustomResourcesFlag) + if (o.ImportVPC.isSet() || o.AdjustVPC.isSet()) && o.DefaultConfig { + return fmt.Errorf("cannot import or configure vpc if --%s is set", defaultConfigFlag) } return nil } @@ -322,7 +322,7 @@ func (o *initEnvOpts) askEnvRegion() error { } func (o *initEnvOpts) askCustomizedResources() error { - if o.NoCustomResources { + if o.DefaultConfig { return nil } if o.ImportVPC.isSet() { @@ -342,7 +342,7 @@ func (o *initEnvOpts) askCustomizedResources() error { return o.askImportResources() case envInitAdjustEnvResourcesSelectOption: return o.askAdjustResources() - case envInitWithNoCustomizedResourcesSelectOption: + case envInitDefaultConfigSelectOption: return nil } return nil @@ -425,7 +425,7 @@ func (o *initEnvOpts) askAdjustResources() error { } func (o *initEnvOpts) importVPCConfig() *deploy.ImportVPCConfig { - if o.NoCustomResources || !o.ImportVPC.isSet() { + if o.DefaultConfig || !o.ImportVPC.isSet() { return nil } return &deploy.ImportVPCConfig{ @@ -436,7 +436,7 @@ func (o *initEnvOpts) importVPCConfig() *deploy.ImportVPCConfig { } func (o *initEnvOpts) adjustVPCConfig() *deploy.AdjustVPCConfig { - if o.NoCustomResources || !o.AdjustVPC.isSet() { + if o.DefaultConfig || !o.AdjustVPC.isSet() { return nil } return &deploy.AdjustVPCConfig{ @@ -585,15 +585,12 @@ func BuildEnvInitCmd() *cobra.Command { Use: "init", Short: "Creates a new environment in your application.", Example: ` - Creates a test environment in your "default" AWS profile. - /code $ copilot env init --name test --profile default + Creates a test environment in your "default" AWS profile using default configuration. + /code $ copilot env init --name test --profile default --default-config Creates a prod-iad environment using your "prod-admin" AWS profile. /code $ copilot env init --name prod-iad --profile prod-admin --prod - Creates a test environment using default environment configuration. - /code $ copilot env init --name test --no-custom-resources - Creates an environment with imported VPC resources. /code $ copilot env init --import-vpc-id vpc-099c32d2b98cdcf47 \ /code --import-public-subnets subnet-013e8b691862966cf,subnet -014661ebb7ab8681a \ @@ -635,7 +632,7 @@ func BuildEnvInitCmd() *cobra.Command { // TODO: use IPNetSliceVar when it is available (https://github.com/spf13/pflag/issues/273). cmd.Flags().StringSliceVar(&vars.AdjustVPC.PublicSubnetCIDRs, publicSubnetCIDRsFlag, nil, publicSubnetCIDRsFlagDescription) cmd.Flags().StringSliceVar(&vars.AdjustVPC.PrivateSubnetCIDRs, privateSubnetCIDRsFlag, nil, privateSubnetCIDRsFlagDescription) - cmd.Flags().BoolVar(&vars.NoCustomResources, noCustomResourcesFlag, false, noCustomResourcesFlagDescription) + cmd.Flags().BoolVar(&vars.DefaultConfig, defaultConfigFlag, false, defaultConfigFlagDescription) flags := pflag.NewFlagSet("Common", pflag.ContinueOnError) flags.AddFlag(cmd.Flags().Lookup(nameFlag)) @@ -644,7 +641,7 @@ func BuildEnvInitCmd() *cobra.Command { flags.AddFlag(cmd.Flags().Lookup(secretAccessKeyFlag)) flags.AddFlag(cmd.Flags().Lookup(sessionTokenFlag)) flags.AddFlag(cmd.Flags().Lookup(regionFlag)) - flags.AddFlag(cmd.Flags().Lookup(noCustomResourcesFlag)) + flags.AddFlag(cmd.Flags().Lookup(defaultConfigFlag)) flags.AddFlag(cmd.Flags().Lookup(prodEnvFlag)) resourcesImportFlag := pflag.NewFlagSet("Import Existing Resources", pflag.ContinueOnError) diff --git a/internal/pkg/cli/env_init_test.go b/internal/pkg/cli/env_init_test.go index 7180c0f7231..7466690535e 100644 --- a/internal/pkg/cli/env_init_test.go +++ b/internal/pkg/cli/env_init_test.go @@ -33,13 +33,13 @@ type initEnvMocks struct { func TestInitEnvOpts_Validate(t *testing.T) { testCases := map[string]struct { - inEnvName string - inAppName string - inNoCustomResources bool - inVPCID string - inPublicIDs []string - inVPCCIDR net.IPNet - inPublicCIDRs []string + inEnvName string + inAppName string + inDefault bool + inVPCID string + inPublicIDs []string + inVPCCIDR net.IPNet + inPublicCIDRs []string inProfileName string inAccessKeyID string @@ -78,12 +78,12 @@ func TestInitEnvOpts_Validate(t *testing.T) { wantedErrMsg: "cannot specify both import vpc flags and configure vpc flags", }, "cannot import or configure resources if use default flag is set": { - inEnvName: "test-pdx", - inAppName: "phonetool", - inNoCustomResources: true, - inVPCID: "mockID", + inEnvName: "test-pdx", + inAppName: "phonetool", + inDefault: true, + inVPCID: "mockID", - wantedErrMsg: fmt.Sprintf("cannot import or configure vpc if --%s is set", noCustomResourcesFlag), + wantedErrMsg: fmt.Sprintf("cannot import or configure vpc if --%s is set", defaultConfigFlag), }, "should err if both profile and access key id are set": { inAppName: "phonetool", @@ -116,8 +116,8 @@ func TestInitEnvOpts_Validate(t *testing.T) { // GIVEN opts := &initEnvOpts{ initEnvVars: initEnvVars{ - Name: tc.inEnvName, - NoCustomResources: tc.inNoCustomResources, + Name: tc.inEnvName, + DefaultConfig: tc.inDefault, AdjustVPC: adjustVPCVars{ PublicSubnetCIDRs: tc.inPublicCIDRs, CIDR: tc.inVPCCIDR, @@ -265,7 +265,7 @@ func TestInitEnvOpts_Ask(t *testing.T) { setupMocks: func(m initEnvMocks) { m.sessProvider.EXPECT().FromProfile(gomock.Any()).Return(mockSession, nil) m.prompt.EXPECT().SelectOne(envInitDefaultEnvConfirmPrompt, "", envInitCustomizedEnvTypes). - Return(envInitWithNoCustomizedResourcesSelectOption, nil) + Return(envInitDefaultConfigSelectOption, nil) }, }, "fail to select VPC": { @@ -426,13 +426,13 @@ func TestInitEnvOpts_Ask(t *testing.T) { // GIVEN addEnv := &initEnvOpts{ initEnvVars: initEnvVars{ - Name: tc.inEnv, - Profile: tc.inProfile, - TempCreds: tc.inTempCreds, - Region: tc.inRegion, - NoCustomResources: tc.inDefault, - AdjustVPC: tc.inAdjustVPCVars, - ImportVPC: tc.inImportVPCVars, + Name: tc.inEnv, + Profile: tc.inProfile, + TempCreds: tc.inTempCreds, + Region: tc.inRegion, + DefaultConfig: tc.inDefault, + AdjustVPC: tc.inAdjustVPCVars, + ImportVPC: tc.inImportVPCVars, GlobalOpts: &GlobalOpts{ prompt: mocks.prompt, }, diff --git a/internal/pkg/cli/flag.go b/internal/pkg/cli/flag.go index cf15c661fe3..6f0c030df24 100644 --- a/internal/pkg/cli/flag.go +++ b/internal/pkg/cli/flag.go @@ -74,7 +74,7 @@ const ( publicSubnetCIDRsFlag = "override-public-cidrs" privateSubnetCIDRsFlag = "override-private-cidrs" - noCustomResourcesFlag = "no-custom-resources" + defaultConfigFlag = "default-config" accessKeyIDFlag = "aws-access-key-id" secretAccessKeyFlag = "aws-secret-access-key" @@ -186,7 +186,7 @@ Tasks with the same group name share the same set of resources. publicSubnetCIDRsFlagDescription = "Optional. CIDR to use for public subnets (default 10.0.0.0/24,10.0.1.0/24)." privateSubnetCIDRsFlagDescription = "Optional. CIDR to use for private subnets (default 10.0.2.0/24,10.0.3.0/24)." - noCustomResourcesFlagDescription = "Optional. Skip prompting and use default environment configuration." + defaultConfigFlagDescription = "Optional. Skip prompting and use default environment configuration." accessKeyIDFlagDescription = "Optional. An AWS access key." secretAccessKeyFlagDescription = "Optional. An AWS secret access key."