Repository: docker/compose-cli
Pull request #1072 (2020-12-16 09:41:13)

Support user passing an ARN for x-aws-vpc
**What I did**
Make x-aws-vpc usage more flexible by detecting use or ARN instead of a vpc ID.
Will avoid more confusion, as custom extension usage, without validation (see https://github.com/compose-spec/compose-go/issues/66), is already error prone

**Related issue**
Reported on community slack

/test-ecs

**(not mandatory) A picture of a cute animal, if possible in relation with what you did**
![image](https://user-images.githubusercontent.com/132757/102331352-07df2280-3f8b-11eb-8eeb-f77edcde5c8d.png)




Patch:
diff --git a/Makefile b/Makefile
index af3a2a91..19bafa71 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@
 #   limitations under the License.
 
 export DOCKER_BUILDKIT=1
+export BUILDX_NO_DEFAULT_LOAD=1
 
 UNAME_S := $(shell uname -s)
 ifeq ($(UNAME_S),Linux)
@@ -44,7 +45,7 @@ cli: ## Compile the cli
 	--output ./bin
 
 e2e-local: ## Run End to end local tests. Set E2E_TEST=TestName to run a single test
-	go test -count=1 -v $(TEST_FLAGS) ./tests/e2e ./tests/compose-e2e ./tests/skip-win-ci-e2e ./local/e2e
+	go test -count=1 -v $(TEST_FLAGS) ./tests/e2e ./tests/skip-win-ci-e2e ./local/e2e
 
 e2e-win-ci: ## Run end to end local tests on Windows CI, no Docker for Linux containers available ATM. Set E2E_TEST=TestName to run a single test
 	go test -count=1 -v $(TEST_FLAGS) ./tests/e2e
diff --git a/ecs/awsResources.go b/ecs/awsResources.go
index d1ff7cf4..26cbed64 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
 		}


Test patch:
diff --git a/ecs/cloudformation_test.go b/ecs/cloudformation_test.go
index 0021114a..e9895e55 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)
diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go
index 44f46128..fdad7d76 100644
--- a/tests/aci-e2e/e2e-aci_test.go
+++ b/tests/aci-e2e/e2e-aci_test.go
@@ -500,12 +500,7 @@ func TestContainerRunAttached(t *testing.T) {
 		l := Lines(res.Stdout())
 		assert.Equal(t, 2, len(l))
 
-		res = c.RunDockerOrExitError("prune", "--force")
-		if strings.Contains(res.Stderr(), "unsupported protocol scheme") { //Flaky strange error on azure SDK call happening only during prune --force
-			time.Sleep(1 * time.Second)
-			res = c.RunDockerCmd("prune", "--force")
-		}
-
+		res = c.RunDockerCmd("prune", "--force")
 		assert.Equal(t, "Deleted resources:\n"+container+"\nTotal CPUs reclaimed: 0.10, total memory reclaimed: 0.10 GB\n", res.Stdout())
 
 		res = c.RunDockerCmd("ps", "--all")
diff --git a/tests/compose-e2e/compose_test.go b/tests/compose-e2e/compose_test.go
index ddf99b51..b5fabb61 100644
--- a/tests/compose-e2e/compose_test.go
+++ b/tests/compose-e2e/compose_test.go
@@ -57,7 +57,7 @@ func TestLocalComposeUp(t *testing.T) {
 		res := c.RunDockerCmd("compose", "ps", "-p", projectName)
 		res.Assert(t, icmd.Expected{Out: `web`})
 
-		endpoint := "http://localhost:90"
+		endpoint := "http://localhost:80"
 		output := HTTPGetWithRetry(t, endpoint+"/words/noun", http.StatusOK, 2*time.Second, 20*time.Second)
 		assert.Assert(t, strings.Contains(output, `"word":`))
 
diff --git a/tests/compose-e2e/fixtures/sentences/docker-compose.yaml b/tests/compose-e2e/fixtures/sentences/docker-compose.yaml
index 42bc5cfa..9ce4902e 100644
--- a/tests/compose-e2e/fixtures/sentences/docker-compose.yaml
+++ b/tests/compose-e2e/fixtures/sentences/docker-compose.yaml
@@ -4,10 +4,10 @@ services:
   words:
     image: gtardif/sentences-api
     ports:
-      - "95:8080"
+      - "8080:8080"
   web:
     image: gtardif/sentences-web
     ports:
-      - "90:80"
+      - "80:80"
     labels:
       - "my-label=test"