diff --git a/internal/pkg/ecs/ecs.go b/internal/pkg/ecs/ecs.go index 02f3f5a473d..53853dfcc19 100644 --- a/internal/pkg/ecs/ecs.go +++ b/internal/pkg/ecs/ecs.go @@ -143,7 +143,7 @@ func (c Client) ServiceConnectServices(app, env, svc string) ([]*ecs.Service, er if err != nil { return nil, fmt.Errorf("get service: %w", err) } - if len(s.Deployments) == 0 { + if len(s.Deployments) == 0 || s.Deployments[0].ServiceConnectConfiguration == nil { return nil, nil } diff --git a/internal/pkg/ecs/ecs_test.go b/internal/pkg/ecs/ecs_test.go index d6e00dc1aba..f58fdfe9f61 100644 --- a/internal/pkg/ecs/ecs_test.go +++ b/internal/pkg/ecs/ecs_test.go @@ -575,6 +575,42 @@ func TestClient_ServiceConnectServices(t *testing.T) { }, wantedError: fmt.Errorf(`get service: get ECS service mockService: some error`), }, + "return early when no deployments": { + setupMocks: func(m clientMocks) { + m.resourceGetter.EXPECT().GetResourcesByTags(serviceResourceType, getRgInput). + Return([]*resourcegroups.Resource{ + {ARN: mockSvcARN}, + }, nil) + m.resourceGetter.EXPECT().GetResourcesByTags(clusterResourceType, getRgEnvClusterInput). + Return([]*resourcegroups.Resource{ + {ARN: "mockARN1"}, {ARN: "mockARN2"}, + }, nil) + m.ecsClient.EXPECT().ActiveClusters("mockARN1", "mockARN2").Return([]string{"mockARN1"}, nil) + m.ecsClient.EXPECT().ActiveServices("mockARN1", []string{mockSvcARN}).Return([]string{mockSvcARN}, nil) + m.ecsClient.EXPECT().Service(mockCluster, mockService).Return(&ecs.Service{ + Deployments: []*awsecs.Deployment{}, + }, nil) + }, + }, + "return early when service connect is not enabled": { + setupMocks: func(m clientMocks) { + m.resourceGetter.EXPECT().GetResourcesByTags(serviceResourceType, getRgInput). + Return([]*resourcegroups.Resource{ + {ARN: mockSvcARN}, + }, nil) + m.resourceGetter.EXPECT().GetResourcesByTags(clusterResourceType, getRgEnvClusterInput). + Return([]*resourcegroups.Resource{ + {ARN: "mockARN1"}, {ARN: "mockARN2"}, + }, nil) + m.ecsClient.EXPECT().ActiveClusters("mockARN1", "mockARN2").Return([]string{"mockARN1"}, nil) + m.ecsClient.EXPECT().ActiveServices("mockARN1", []string{mockSvcARN}).Return([]string{mockSvcARN}, nil) + m.ecsClient.EXPECT().Service(mockCluster, mockService).Return(&ecs.Service{ + Deployments: []*awsecs.Deployment{ + {}, + }, + }, nil) + }, + }, "error listing namespace": { setupMocks: func(m clientMocks) { m.resourceGetter.EXPECT().GetResourcesByTags(serviceResourceType, getRgInput).