in internal/pkg/cli/env_init.go [475:548]
func (o *initEnvOpts) askImportResources() error {
if o.selVPC == nil {
o.selVPC = selector.NewEC2Select(o.prompt, ec2.New(o.sess))
}
if o.importVPC.ID == "" {
vpcID, err := o.selVPC.VPC(envInitVPCSelectPrompt, "")
if err != nil {
if err == selector.ErrVPCNotFound {
log.Errorf(`No existing VPCs were found. You can either:
- Create a new VPC first and then import it.
- Use the default Copilot environment configuration.
`)
}
return fmt.Errorf("select VPC: %w", err)
}
o.importVPC.ID = vpcID
}
if o.ec2Client == nil {
o.ec2Client = ec2.New(o.sess)
}
dnsSupport, err := o.ec2Client.HasDNSSupport(o.importVPC.ID)
if err != nil {
return fmt.Errorf("check if VPC %s has DNS support enabled: %w", o.importVPC.ID, err)
}
if !dnsSupport {
log.Errorln(`Looks like you're creating an environment using a VPC with DNS support *disabled*.
Copilot cannot create services or jobs in VPCs without DNS support. We recommend enabling this property.
To learn more about the issue:
https://aws.amazon.com/premiumsupport/knowledge-center/ecs-pull-container-api-error-ecr/`)
return fmt.Errorf("VPC %s has no DNS support enabled", o.importVPC.ID)
}
if o.importVPC.PublicSubnetIDs == nil {
publicSubnets, err := o.selVPC.Subnets(selector.SubnetsInput{
Msg: envInitPublicSubnetsSelectPrompt,
Help: "",
VPCID: o.importVPC.ID,
IsPublic: true,
})
if err != nil {
if errors.Is(err, selector.ErrSubnetsNotFound) {
log.Warningf(`No existing subnets were found in VPC %s.
If you proceed without at least two public subnets, you will not be able to deploy Load Balanced Web Services in this environment.
`, o.importVPC.ID)
} else {
return fmt.Errorf("select public subnets: %w", err)
}
}
if len(publicSubnets) == 1 {
return errors.New("select public subnets: at least two public subnets must be selected to enable Load Balancing")
}
o.importVPC.PublicSubnetIDs = publicSubnets
}
if o.importVPC.PrivateSubnetIDs == nil {
privateSubnets, err := o.selVPC.Subnets(selector.SubnetsInput{
Msg: envInitPrivateSubnetsSelectPrompt,
Help: "",
VPCID: o.importVPC.ID,
IsPublic: false,
})
if err != nil {
if err == selector.ErrSubnetsNotFound {
log.Errorf(`No existing subnets were found in VPC %s. You can either:
- Create new private subnets and then import them.
- Use the default Copilot environment configuration.`, o.importVPC.ID)
}
return fmt.Errorf("select private subnets: %w", err)
}
if len(privateSubnets) < 2 {
return errors.New("select private subnets: at least two private subnets must be selected")
}
o.importVPC.PrivateSubnetIDs = privateSubnets
}
return nil
}