Skip to content

chore(cli): enable customized env resources by flags#1232

Merged
mergify[bot] merged 5 commits intoaws:masterfrom
iamhopaul123:env-init/enable-customized-resources
Aug 6, 2020
Merged

chore(cli): enable customized env resources by flags#1232
mergify[bot] merged 5 commits intoaws:masterfrom
iamhopaul123:env-init/enable-customized-resources

Conversation

@iamhopaul123
Copy link
Copy Markdown
Contributor

Part of #1192. Enable customized env resources by flags. UI change to env init is not included.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@iamhopaul123 iamhopaul123 requested a review from efekarakus August 5, 2020 05:45
@iamhopaul123 iamhopaul123 requested a review from a team as a code owner August 5, 2020 05:45
@iamhopaul123 iamhopaul123 force-pushed the env-init/enable-customized-resources branch from 50aab3d to 9f38240 Compare August 5, 2020 05:52
@iamhopaul123
Copy link
Copy Markdown
Contributor Author

iamhopaul123 commented Aug 5, 2020

Help Menu

Creates a new environment in your application.

Usage
  copilot env init [flags]

Required Flags
  -n, --name string      Name of the environment.
      --profile string   Name of the profile.

Import Existing Resources Flags
      --import-private-subnets strings   Optional. Use existing private subnet IDs.
      --import-public-subnets strings    Optional. Use existing public subnet IDs.
      --import-vpc-id string             Optional. Use an existing VPC ID.

Configure Default Resources Flags
      --override-private-cidrs strings   Optional. CIDR to use for private subnets (default 10.0.2.0/24,10.0.3.0/24).
      --override-public-cidrs strings    Optional. CIDR to use for public subnets (default 10.0.0.0/24,10.0.1.0/24).
      --override-vpc-cidr ipNet          Optional. Global CIDR to use for VPC (default 10.0.0.0/16).

Optional Flags
      --prod          If the environment contains production services.
      --use-default   Optional. Skip prompting and use default environment configuration.

Global Flags
  -a, --app string   Name of the application.

Examples
  Creates a test environment in your "default" AWS profile.
  `$ copilot env init --name test --profile default`

  Creates a prod-iad environment using your "prod-admin" AWS profile.
  `$ copilot env init --name prod-iad --profile prod-admin --prod`

  Creates an environment with imported VPC resources.
  `$ copilot env init --import-vpc-id vpc-099c32d2b98cdcf47`
  `--import-public-subnets subnet-013e8b691862966cf,subnet -014661ebb7ab8681a`
  `--import-private-subnets subnet-055fafef48fb3c547,subnet-00c9e76f288363e7f`

  Creates an environment with overrided CIDRs.
  `$ copilot env init --override-vpc-cidr 10.1.0.0/16`
  `--override-public-cidrs 10.1.0.0/24,10.1.1.0/24`
  `--override-private-cidrs 10.1.2.0/24,10.1.3.0/24`

Manual Test

$ copilot env init --import-vpc-id vpc-099c32d2b98cdcf47 --import-public-subnets subnet-013e8b691862966cf,subnet -014661ebb7ab8681a --import-private-subnets subnet-055fafef48fb3c547,subnet-00c9e76f288363e7f

What is your environment's name? test2
Which named profile should we use to create test2? default
✔ Created the infrastructure for the test2 environment.
- Virtual private cloud on 2 availability zones to hold your services     [In Progress]
- Virtual private cloud on 2 availability zones to hold your services     [In Progress]
  - Internet gateway to connect the network to the internet               [In Progress]
  - Public subnets for internet facing services                           [In Progress]
  - Private subnets for services that can't be reached from the internet  [In Progress]
  - Routing tables for services to talk with each other                   [In Progress]
- ECS Cluster to hold your services                                       [Complete]
- Application load balancer to distribute traffic                         [Complete]
✔ Linked account 403971813171 and region us-west-2 to application my-project.

✔ Created environment test2 in region us-west-2 under application my-project.

Comment thread internal/pkg/cli/env_init.go Outdated
return nil
}

func (o *initEnvOpts) validateCustomizedResources() error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: validateCustomizedVPC

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning to make it more extendable so that when we have more types of customized resources available, we can add the validation in this function. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I wasn't sure. I personally like naming things with what they represent now if I'm not certain how it'll evolve. But this is perfectly fine and understandable.

Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/flag.go Outdated
@iamhopaul123 iamhopaul123 force-pushed the env-init/enable-customized-resources branch from 61678de to dad3aa1 Compare August 5, 2020 21:28
@iamhopaul123 iamhopaul123 requested a review from a team August 5, 2020 21:29
Copy link
Copy Markdown
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! just two more minor comments

Comment thread internal/pkg/cli/env_init.go Outdated
Comment thread internal/pkg/cli/env_init.go Outdated
return nil
}

func (o *initEnvOpts) validateCustomizedResources() error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I wasn't sure. I personally like naming things with what they represent now if I'm not certain how it'll evolve. But this is perfectly fine and understandable.

@iamhopaul123 iamhopaul123 force-pushed the env-init/enable-customized-resources branch from 02287ea to e388750 Compare August 5, 2020 21:49
@iamhopaul123 iamhopaul123 requested a review from a team August 5, 2020 23:11
Comment on lines +59 to +65
if len(v.PublicSubnetIDs) != 0 {
return true
}
if len(v.PrivateSubnetIDs) != 0 {
return true
}
return false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if len(v.PublicSubnetIDs) != 0 {
return true
}
if len(v.PrivateSubnetIDs) != 0 {
return true
}
return false
return len(v.PublicSubnetIDs) > 0 || len(v.PrivateSubnetIDs) > 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll address all feedbacks in my next one!

Comment on lines +79 to +85
if len(v.PublicSubnetCIDRs) != 0 {
return true
}
if len(v.PrivateSubnetCIDRs) != 0 {
return true
}
return false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps same?

}

func (o *initEnvOpts) askEnvProfile() error {
// TODO: add this behavior to selector pkg.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@mergify mergify bot merged commit 340cf3e into aws:master Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants