From 1b9a8ea6254f41b4aa434e5cf68056af1a3c4031 Mon Sep 17 00:00:00 2001 From: Andrew Hammond Date: Mon, 10 Feb 2020 09:32:33 -0800 Subject: [PATCH] WIP: cluster support --- .../lib/ecs/deploy-action.ts | 2 +- .../@aws-cdk/aws-ecs/lib/base/base-service.ts | 5 ++++ .../@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts | 22 +++++++++++++++++- .../aws-ecs/lib/fargate/fargate-service.ts | 23 ++++++++++++++++++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts index 245764f12bb56..c7bc50dccf5c8 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts @@ -39,7 +39,7 @@ export interface EcsDeployActionProps extends codepipeline.CommonAwsActionProps /** * The ECS Service to deploy. */ - readonly service: ecs.BaseService; + readonly service: ecs.IBaseService; } /** diff --git a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts index fe6a28b14943b..cedaae243ff09 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts @@ -29,6 +29,11 @@ export interface IService extends IResource { * @attribute */ readonly serviceName: string; + +} + +export interface IBaseService extends IService { + readonly cluster: ICluster; } /** diff --git a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts index 980a2072810f8..72009bf22935c 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts @@ -1,7 +1,14 @@ import * as ec2 from '@aws-cdk/aws-ec2'; import * as cdk from '@aws-cdk/core'; import { Construct, Lazy, Resource, Stack } from '@aws-cdk/core'; -import { BaseService, BaseServiceOptions, IService, LaunchType, PropagatedTagSource } from '../base/base-service'; +import { + BaseService, + BaseServiceOptions, + IBaseService, + IService, + LaunchType, + PropagatedTagSource +} from '../base/base-service'; import { NetworkMode, TaskDefinition } from '../base/task-definition'; import { CfnService } from '../ecs.generated'; import { PlacementConstraint, PlacementStrategy } from '../placement'; @@ -111,6 +118,19 @@ export class Ec2Service extends BaseService implements IEc2Service { return new Import(scope, id); } + /** + * Import a service definition from the specified service attributes. + */ + public static fromEc2ServiceAttributes(scope: Construct, id: string, attributes: string): IBaseService { + class Import extends Resource implements IBaseService { + public readonly cluster = ; + public readonly serviceArn = fargateServiceArn; + public readonly serviceName = matcher.exec(fargateServiceArn)[0]; + } + return new Import(scope, id) + } + + private readonly constraints: CfnService.PlacementConstraintProperty[]; private readonly strategies: CfnService.PlacementStrategyProperty[]; private readonly daemon: boolean; diff --git a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts index 578c06d9040f0..3a569a2a2e52a 100644 --- a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts @@ -1,6 +1,13 @@ import * as ec2 from '@aws-cdk/aws-ec2'; import * as cdk from '@aws-cdk/core'; -import { BaseService, BaseServiceOptions, IService, LaunchType, PropagatedTagSource } from '../base/base-service'; +import { + BaseService, + BaseServiceOptions, + IBaseService, + IService, + LaunchType, + PropagatedTagSource +} from '../base/base-service'; import { TaskDefinition } from '../base/task-definition'; /** @@ -87,6 +94,20 @@ export class FargateService extends BaseService implements IFargateService { return new Import(scope, id); } + /** + * Import a service definition from the specified service attributes. + */ + public static fromFargateServiceAttributes(scope: cdk.Construct, id: string, attributes: string): IBaseService { + const matcher = new RegExp(/arn:[^:]+:ecs:[^:]+[^:]+:[^:]+:service\/(.*)/); + class Import extends cdk.Resource implements IBaseService { + public readonly cluster = ; + public readonly serviceArn = fargateServiceArn; + public readonly serviceName = matcher.exec(fargateServiceArn)[0]; + } + return new Import(scope, id); + } + + /** * Constructs a new instance of the FargateService class. */