diff --git a/ecs/awsResources.go b/ecs/awsResources.go index d1ff7cf4f..26cbed64b 100644 --- a/ecs/awsResources.go +++ b/ecs/awsResources.go @@ -25,6 +25,7 @@ import ( "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/errdefs" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/awslabs/goformation/v4/cloudformation" "github.com/awslabs/goformation/v4/cloudformation/ec2" @@ -168,7 +169,15 @@ func (b *ecsAPIService) parseVPCExtension(ctx context.Context, project *types.Pr var vpc string if x, ok := project.Extensions[extensionVPC]; ok { vpc = x.(string) - err := b.aws.CheckVPC(ctx, vpc) + ARN, err := arn.Parse(vpc) + if err == nil { + // User has set an ARN, like the one Terraform shows as output, while we expect an ID + id := ARN.Resource + i := strings.LastIndex(id, "/") + vpc = id[i+1:] + } + + err = b.aws.CheckVPC(ctx, vpc) if err != nil { return "", nil, err } diff --git a/ecs/cloudformation_test.go b/ecs/cloudformation_test.go index 0021114a2..e9895e556 100644 --- a/ecs/cloudformation_test.go +++ b/ecs/cloudformation_test.go @@ -543,6 +543,23 @@ services: assert.Equal(t, template.Metadata["Cluster"], "arn:aws:ecs:region:account:cluster/name") } +func TestARNUsedAsVpcID(t *testing.T) { + convertYaml(t, ` +x-aws-vpc: "arn:aws:ec2:us-west-1:EXAMPLE:vpc/vpc-1234acbd" +services: + test: + image: nginx +`, func(m *MockAPIMockRecorder) { + m.CheckVPC(gomock.Any(), "vpc-1234acbd").Return(nil) + m.GetSubNets(gomock.Any(), "vpc-1234acbd").Return([]awsResource{ + existingAWSResource{id: "subnet1"}, + existingAWSResource{id: "subnet2"}, + }, nil) + m.IsPublicSubnet(gomock.Any(), "subnet1").Return(true, nil) + m.IsPublicSubnet(gomock.Any(), "subnet2").Return(true, nil) + }) +} + func convertYaml(t *testing.T, yaml string, fn ...func(m *MockAPIMockRecorder)) *cloudformation.Template { project := loadConfig(t, yaml) ctrl := gomock.NewController(t)