Merge pull request #562 from docker/dns

Check VPC has DNS resolution enabled
This commit is contained in:
Nicolas De loof 2020-08-28 19:57:20 +02:00 committed by GitHub
commit ed1776fec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 12 deletions

View File

@ -105,10 +105,19 @@ func (s sdk) CreateCluster(ctx context.Context, name string) (string, error) {
return *response.Cluster.Status, nil
}
func (s sdk) VpcExists(ctx context.Context, vpcID string) (bool, error) {
logrus.Debug("CheckRequirements if VPC exists: ", vpcID)
_, err := s.EC2.DescribeVpcsWithContext(ctx, &ec2.DescribeVpcsInput{VpcIds: []*string{&vpcID}})
return err == nil, err
func (s sdk) CheckVPC(ctx context.Context, vpcID string) error {
logrus.Debug("CheckRequirements on VPC : ", vpcID)
output, err := s.EC2.DescribeVpcAttributeWithContext(ctx, &ec2.DescribeVpcAttributeInput{
VpcId: aws.String(vpcID),
Attribute: aws.String("enableDnsSupport"),
})
if err != nil {
return err
}
if !*output.EnableDnsSupport.Value {
return fmt.Errorf("VPC %q doesn't have DNS resolution enabled", vpcID)
}
return err
}
func (s sdk) GetDefaultVPC(ctx context.Context) (string, error) {

View File

@ -103,23 +103,23 @@ func (b *ecsAPIService) Up(ctx context.Context, project *types.Project) error {
}
func (b ecsAPIService) GetVPC(ctx context.Context, project *types.Project) (string, error) {
var vpcID string
//check compose file for custom VPC selected
if vpc, ok := project.Extensions[extensionVPC]; ok {
vpcID := vpc.(string)
ok, err := b.SDK.VpcExists(ctx, vpcID)
vpcID = vpc.(string)
} else {
defaultVPC, err := b.SDK.GetDefaultVPC(ctx)
if err != nil {
return "", err
}
if !ok {
return "", fmt.Errorf("VPC does not exist: %s", vpc)
}
return vpcID, nil
vpcID = defaultVPC
}
defaultVPC, err := b.SDK.GetDefaultVPC(ctx)
err := b.SDK.CheckVPC(ctx, vpcID)
if err != nil {
return "", err
}
return defaultVPC, nil
return vpcID, nil
}
func (b ecsAPIService) GetLoadBalancer(ctx context.Context, project *types.Project) (string, error) {