Check VPC has DNS resolution enabled

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-08-28 10:57:31 +02:00
parent f80e90caca
commit cd27fcb9c8
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
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)
if err != nil {
return "", err
}
if !ok {
return "", fmt.Errorf("VPC does not exist: %s", vpc)
}
return vpcID, nil
}
vpcID = vpc.(string)
} else {
defaultVPC, err := b.SDK.GetDefaultVPC(ctx)
if err != nil {
return "", err
}
return defaultVPC, nil
vpcID = defaultVPC
}
err := b.SDK.CheckVPC(ctx, vpcID)
if err != nil {
return "", err
}
return vpcID, nil
}
func (b ecsAPIService) GetLoadBalancer(ctx context.Context, project *types.Project) (string, error) {