From 33a35b9928d94563b28f0899fb253578785fc0b0 Mon Sep 17 00:00:00 2001 From: Hsing-Hui Hsu Date: Mon, 5 Nov 2018 15:54:07 -0800 Subject: [PATCH] One EcsCluster to Rule Them All --- .../@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts | 4 +- .../{ec2/ec2-cluster.ts => ecs-cluster.ts} | 61 +++++++++---- .../aws-ecs/lib/fargate/fargate-cluster.ts | 87 ------------------- .../aws-ecs/lib/fargate/fargate-service.ts | 4 +- packages/@aws-cdk/aws-ecs/lib/index.ts | 3 +- .../aws-ecs/lib/load-balanced-ecs-service.ts | 4 +- .../load-balanced-fargate-service-applet.ts | 4 +- .../lib/load-balanced-fargate-service.ts | 4 +- .../aws-ecs/test/ec2/integ.lb-awsvpc-nw.ts | 2 +- .../aws-ecs/test/ec2/integ.lb-bridge-nw.ts | 2 +- .../aws-ecs/test/ec2/test.ec2-service.ts | 30 +++---- .../aws-ecs/test/fargate/integ.asset-image.ts | 2 +- .../test/fargate/integ.lb-awsvpc-nw.ts | 2 +- .../test/fargate/test.fargate-cluster.ts | 41 --------- .../test/fargate/test.fargate-service.ts | 8 +- ...est.ec2-cluster.ts => test.ecs-cluster.ts} | 22 ++--- packages/@aws-cdk/aws-ecs/test/test.l3s.ts | 4 +- 17 files changed, 93 insertions(+), 191 deletions(-) rename packages/@aws-cdk/aws-ecs/lib/{ec2/ec2-cluster.ts => ecs-cluster.ts} (83%) delete mode 100644 packages/@aws-cdk/aws-ecs/lib/fargate/fargate-cluster.ts delete mode 100644 packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-cluster.ts rename packages/@aws-cdk/aws-ecs/test/{ec2/test.ec2-cluster.ts => test.ecs-cluster.ts} (87%) 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 f035a97fc8363..73949090efbab 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts @@ -4,8 +4,8 @@ import elb = require('@aws-cdk/aws-elasticloadbalancing'); import cdk = require('@aws-cdk/cdk'); import { BaseService, BaseServiceProps } from '../base/base-service'; import { NetworkMode } from '../base/task-definition'; +import { IEcsCluster } from '../ecs-cluster'; import { cloudformation } from '../ecs.generated'; -import { IEc2Cluster } from './ec2-cluster'; import { Ec2TaskDefinition } from './ec2-task-definition'; /** @@ -15,7 +15,7 @@ export interface Ec2ServiceProps extends BaseServiceProps { /** * Cluster where service will be deployed */ - cluster: IEc2Cluster; + cluster: IEcsCluster; /** * Task Definition used for running tasks in the service diff --git a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-cluster.ts b/packages/@aws-cdk/aws-ecs/lib/ecs-cluster.ts similarity index 83% rename from packages/@aws-cdk/aws-ecs/lib/ec2/ec2-cluster.ts rename to packages/@aws-cdk/aws-ecs/lib/ecs-cluster.ts index 86638fa95e63b..95966609d1204 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-cluster.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ecs-cluster.ts @@ -3,24 +3,34 @@ import cloudwatch = require ('@aws-cdk/aws-cloudwatch'); import ec2 = require('@aws-cdk/aws-ec2'); import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); -import { BaseCluster, BaseClusterProps } from '../base/base-cluster'; +import { cloudformation } from './ecs.generated'; /** * Properties to define an ECS cluster */ -// tslint:disable-next-line:no-empty-interface -export interface Ec2ClusterProps extends BaseClusterProps { +export interface EcsClusterProps { + /** + * A name for the cluster. + * + * @default CloudFormation-generated name + */ + clusterName?: string; + + /** + * The VPC where your ECS instances will be running or your ENIs will be deployed + */ + vpc: ec2.VpcNetworkRef; } /** * A container cluster that runs on your EC2 instances */ -export class Ec2Cluster extends BaseCluster implements IEc2Cluster { +export class EcsCluster extends cdk.Construct implements IEcsCluster { /** * Import an existing cluster */ - public static import(parent: cdk.Construct, name: string, props: ImportedEc2ClusterProps): IEc2Cluster { - return new ImportedEc2Cluster(parent, name, props); + public static import(parent: cdk.Construct, name: string, props: ImportedEcsClusterProps): IEcsCluster { + return new ImportedEcsCluster(parent, name, props); } /** @@ -28,8 +38,29 @@ export class Ec2Cluster extends BaseCluster implements IEc2Cluster { */ public readonly connections: ec2.Connections = new ec2.Connections(); - constructor(parent: cdk.Construct, name: string, props: Ec2ClusterProps) { - super(parent, name, props); + /** + * The VPC this cluster was created in. + */ + public readonly vpc: ec2.VpcNetworkRef; + + /** + * The ARN of this cluster + */ + public readonly clusterArn: string; + + /** + * The name of this cluster + */ + public readonly clusterName: string; + + constructor(parent: cdk.Construct, name: string, props: EcsClusterProps) { + super(parent, name); + + const cluster = new cloudformation.ClusterResource(this, 'Resource', {clusterName: props.clusterName}); + + this.vpc = props.vpc; + this.clusterArn = cluster.clusterArn; + this.clusterName = cluster.clusterName; } /** @@ -84,9 +115,9 @@ export class Ec2Cluster extends BaseCluster implements IEc2Cluster { } /** - * Export the Ec2Cluster + * Export the EcsCluster */ - public export(): ImportedEc2ClusterProps { + public export(): ImportedEcsClusterProps { return { clusterName: new cdk.Output(this, 'ClusterName', { value: this.clusterName }).makeImportValue().toString(), vpc: this.vpc.export(), @@ -149,7 +180,7 @@ export class EcsOptimizedAmi implements ec2.IMachineImageSource { /** * An ECS cluster */ -export interface IEc2Cluster { +export interface IEcsCluster { /** * Name of the cluster */ @@ -169,7 +200,7 @@ export interface IEc2Cluster { /** * Properties to import an ECS cluster */ -export interface ImportedEc2ClusterProps { +export interface ImportedEcsClusterProps { /** * Name of the cluster */ @@ -187,9 +218,9 @@ export interface ImportedEc2ClusterProps { } /** - * An Ec2Cluster that has been imported + * An EcsCluster that has been imported */ -class ImportedEc2Cluster extends cdk.Construct implements IEc2Cluster { +class ImportedEcsCluster extends cdk.Construct implements IEcsCluster { /** * Name of the cluster */ @@ -205,7 +236,7 @@ class ImportedEc2Cluster extends cdk.Construct implements IEc2Cluster { */ public readonly connections = new ec2.Connections(); - constructor(parent: cdk.Construct, name: string, props: ImportedEc2ClusterProps) { + constructor(parent: cdk.Construct, name: string, props: ImportedEcsClusterProps) { super(parent, name); this.clusterName = props.clusterName; this.vpc = ec2.VpcNetworkRef.import(this, "vpc", props.vpc); diff --git a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-cluster.ts b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-cluster.ts deleted file mode 100644 index a720237127eea..0000000000000 --- a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-cluster.ts +++ /dev/null @@ -1,87 +0,0 @@ -import ec2 = require('@aws-cdk/aws-ec2'); -import cdk = require('@aws-cdk/cdk'); -import { BaseCluster, BaseClusterProps } from '../base/base-cluster'; - -/** - * Properties to define a Fargate cluster - */ -// tslint:disable-next-line:no-empty-interface -export interface FargateClusterProps extends BaseClusterProps { -} - -/** - * Define a cluster to run tasks on managed instances - */ -export class FargateCluster extends BaseCluster implements IFargateCluster { - /** - * Import an existing Fargate cluster - */ - public static import(parent: cdk.Construct, name: string, props: ImportedFargateClusterProps): IFargateCluster { - return new ImportedFargateCluster(parent, name, props); - } - - constructor(parent: cdk.Construct, name: string, props: FargateClusterProps) { - super(parent, name, props); - } - - /** - * Export the FargateCluster - */ - public export(): ImportedFargateClusterProps { - return { - clusterName: new cdk.Output(this, 'ClusterName', { value: this.clusterName }).makeImportValue().toString(), - vpc: this.vpc.export(), - }; - } -} - -/** - * A Fargate cluster - */ -export interface IFargateCluster { - /** - * Name of the cluster - */ - readonly clusterName: string; - - /** - * VPC where Task ENIs will be placed - */ - readonly vpc: ec2.VpcNetworkRef; -} - -/** - * Properties to import a Fargate cluster - */ -export interface ImportedFargateClusterProps { - /** - * Name of the cluster - */ - clusterName: string; - - /** - * VPC where Task ENIs should be placed - */ - vpc: ec2.VpcNetworkRefProps; -} - -/** - * A FargateCluster that has been imported - */ -class ImportedFargateCluster extends cdk.Construct implements IFargateCluster { - /** - * Name of the cluster - */ - public readonly clusterName: string; - - /** - * VPC where ENIs will be placed - */ - public readonly vpc: ec2.VpcNetworkRef; - - constructor(parent: cdk.Construct, name: string, props: ImportedFargateClusterProps) { - super(parent, name); - this.clusterName = props.clusterName; - this.vpc = ec2.VpcNetworkRef.import(this, "vpc", props.vpc); - } -} \ No newline at end of file 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 ea2c346898744..2ac3034576e12 100644 --- a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts @@ -1,7 +1,7 @@ import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); import { BaseService, BaseServiceProps } from '../base/base-service'; -import { IFargateCluster } from './fargate-cluster'; +import { IEcsCluster } from '../ecs-cluster'; import { FargateTaskDefinition } from './fargate-task-definition'; /** @@ -11,7 +11,7 @@ export interface FargateServiceProps extends BaseServiceProps { /** * Cluster where service will be deployed */ - cluster: IFargateCluster; // should be required? do we assume 'default' exists? + cluster: IEcsCluster; // should be required? do we assume 'default' exists? /** * Task Definition used for running tasks in the service diff --git a/packages/@aws-cdk/aws-ecs/lib/index.ts b/packages/@aws-cdk/aws-ecs/lib/index.ts index f98ac058f0f81..1d1ce147d705f 100644 --- a/packages/@aws-cdk/aws-ecs/lib/index.ts +++ b/packages/@aws-cdk/aws-ecs/lib/index.ts @@ -5,12 +5,11 @@ export * from './base/task-definition'; export * from './container-definition'; export * from './container-image'; +export * from './ecs-cluster'; -export * from './ec2/ec2-cluster'; export * from './ec2/ec2-service'; export * from './ec2/ec2-task-definition'; -export * from './fargate/fargate-cluster'; export * from './fargate/fargate-service'; export * from './fargate/fargate-task-definition'; diff --git a/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts index 62487d7d00ec2..22264cdd92295 100644 --- a/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts @@ -1,9 +1,9 @@ import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); import cdk = require('@aws-cdk/cdk'); import { IContainerImage } from './container-image'; -import { IEc2Cluster } from './ec2/ec2-cluster'; import { Ec2Service } from './ec2/ec2-service'; import { Ec2TaskDefinition } from './ec2/ec2-task-definition'; +import { IEcsCluster } from './ecs-cluster'; /** * Properties for a LoadBalancedEc2Service @@ -12,7 +12,7 @@ export interface LoadBalancedEc2ServiceProps { /** * The cluster where your Fargate service will be deployed */ - cluster: IEc2Cluster; + cluster: IEcsCluster; /** * The image to start. diff --git a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts index 274a664ff6ef4..8127794bb245d 100644 --- a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts +++ b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts @@ -1,7 +1,7 @@ import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); import { DockerHub } from './container-image'; -import { FargateCluster } from './fargate/fargate-cluster'; +import { EcsCluster } from './ecs-cluster'; import { LoadBalancedFargateService } from './load-balanced-fargate-service'; /** @@ -80,7 +80,7 @@ export class LoadBalancedFargateServiceApplet extends cdk.Stack { super(parent, id, props); const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); - const cluster = new FargateCluster(this, 'Cluster', { vpc }); + const cluster = new EcsCluster(this, 'Cluster', { vpc }); // Instantiate Fargate Service with just cluster and image new LoadBalancedFargateService(this, "FargateService", { diff --git a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts index 474048ec8f7e6..028b8fd5913d4 100644 --- a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts @@ -1,7 +1,7 @@ import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); import cdk = require('@aws-cdk/cdk'); import { IContainerImage } from './container-image'; -import { IFargateCluster } from './fargate/fargate-cluster'; +import { IEcsCluster } from './ecs-cluster'; import { FargateService } from './fargate/fargate-service'; import { FargateTaskDefinition } from './fargate/fargate-task-definition'; @@ -12,7 +12,7 @@ export interface LoadBalancedFargateServiceProps { /** * The cluster where your Fargate service will be deployed */ - cluster: IFargateCluster; + cluster: IEcsCluster; /** * The image to start diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.ts b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.ts index c61b06a7c338d..de0f3419af31f 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.ts @@ -9,7 +9,7 @@ const stack = new cdk.Stack(app, 'aws-ecs-integ'); const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 }); -const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); +const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); cluster.addDefaultAutoScalingGroupCapacity({ instanceType: new ec2.InstanceType('t2.micro') }); diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.ts b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.ts index 8c00625228206..75bb468b9660d 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.ts @@ -9,7 +9,7 @@ const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs'); const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 }); -const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); +const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); cluster.addDefaultAutoScalingGroupCapacity({ instanceType: new ec2.InstanceType('t2.micro') }); diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts b/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts index f51f5d21fa361..d7677be0e0254 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts @@ -12,7 +12,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -31,7 +31,7 @@ export = { Ref: "Ec2TaskDef0226F28C" }, Cluster: { - Ref: "Ec2ClusterEE43E89D" + Ref: "EcsCluster97242B84" }, DeploymentConfiguration: { MaximumPercent: 200, @@ -52,7 +52,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); // THEN @@ -72,7 +72,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); // THEN @@ -90,7 +90,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -117,7 +117,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef', { networkMode: NetworkMode.AwsVpc }); @@ -168,7 +168,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -196,7 +196,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -226,7 +226,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -256,7 +256,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -282,7 +282,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc'); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -311,7 +311,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc'); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -337,7 +337,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -367,7 +367,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); taskDefinition.addContainer("web", { @@ -395,7 +395,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'VPC'); - const cluster = new ecs.Ec2Cluster(stack, 'Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'Cluster', { vpc }); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TD', { networkMode: ecs.NetworkMode.Host }); const container = taskDefinition.addContainer('web', { image: ecs.DockerHub.image('test'), diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/integ.asset-image.ts b/packages/@aws-cdk/aws-ecs/test/fargate/integ.asset-image.ts index 4366cf2ae6722..99b9ca43d8808 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/integ.asset-image.ts +++ b/packages/@aws-cdk/aws-ecs/test/fargate/integ.asset-image.ts @@ -7,7 +7,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-ecs-integ'); const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 }); -const cluster = new ecs.FargateCluster(stack, 'Cluster', { vpc }); +const cluster = new ecs.EcsCluster(stack, 'Cluster', { vpc }); Array.isArray(cluster); Array.isArray(path); diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.ts b/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.ts index b3c6f9401d46a..7921fa2a4f55f 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.ts +++ b/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.ts @@ -8,7 +8,7 @@ const stack = new cdk.Stack(app, 'aws-ecs-integ'); const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 }); -const cluster = new ecs.FargateCluster(stack, 'FargateCluster', { vpc }); +const cluster = new ecs.EcsCluster(stack, 'FargateCluster', { vpc }); const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef', { memoryMiB: '1GB', diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-cluster.ts b/packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-cluster.ts deleted file mode 100644 index f25bcaf95985e..0000000000000 --- a/packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-cluster.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { expect, haveResource } from '@aws-cdk/assert'; -import ec2 = require('@aws-cdk/aws-ec2'); -import cdk = require('@aws-cdk/cdk'); -import { Test } from 'nodeunit'; -import ecs = require('../../lib'); - -export = { - "When creating a Fargate Cluster": { - "with only required properties set, it correctly sets default properties"(test: Test) { - // GIVEN - const stack = new cdk.Stack(); - const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - new ecs.FargateCluster(stack, 'FargateCluster', { - vpc, - }); - - expect(stack).to(haveResource("AWS::ECS::Cluster")); - - expect(stack).to(haveResource("AWS::EC2::VPC", { - CidrBlock: '10.0.0.0/16', - EnableDnsHostnames: true, - EnableDnsSupport: true, - InstanceTenancy: ec2.DefaultInstanceTenancy.Default, - Tags: [ - { - Key: "Name", - Value: "MyVpc" - } - ] - })); - - expect(stack).notTo(haveResource("AWS::EC2::SecurityGroup")); - expect(stack).notTo(haveResource("AWS::AutoScaling::LaunchConfiguration")); - expect(stack).notTo(haveResource("AWS::AutoScaling::AutoScalingGroup")); - expect(stack).notTo(haveResource("AWS::IAM::Role")); - expect(stack).notTo(haveResource("AWS::IAM::Policy")); - - test.done(); - }, - } -}; diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-service.ts b/packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-service.ts index 30132983d62a7..48a2d05ac29b2 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-service.ts @@ -10,7 +10,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.FargateCluster(stack, 'FargateCluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); taskDefinition.addContainer("web", { @@ -28,7 +28,7 @@ export = { Ref: "FargateTaskDefC6FB60B4" }, Cluster: { - Ref: "FargateCluster7CCD5F93" + Ref: "EcsCluster97242B84" }, DeploymentConfiguration: { MaximumPercent: 200, @@ -85,7 +85,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.FargateCluster(stack, 'FargateCluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); // THEN @@ -103,7 +103,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.FargateCluster(stack, 'FargateCluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); taskDefinition.addContainer("web", { diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-cluster.ts b/packages/@aws-cdk/aws-ecs/test/test.ecs-cluster.ts similarity index 87% rename from packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-cluster.ts rename to packages/@aws-cdk/aws-ecs/test/test.ecs-cluster.ts index fab9632d2a261..6d5d716d2bc3e 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-cluster.ts +++ b/packages/@aws-cdk/aws-ecs/test/test.ecs-cluster.ts @@ -3,7 +3,7 @@ import ec2 = require('@aws-cdk/aws-ec2'); import { InstanceType } from '@aws-cdk/aws-ec2'; import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; -import ecs = require('../../lib'); +import ecs = require('../lib'); export = { "When creating an ECS Cluster": { @@ -11,7 +11,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc, }); @@ -38,12 +38,12 @@ export = { ImageId: "", // Should this not be the latest image ID? InstanceType: "t2.micro", IamInstanceProfile: { - Ref: "Ec2ClusterDefaultAutoScalingGroupInstanceProfileDB232471" + Ref: "EcsClusterDefaultAutoScalingGroupInstanceProfile2CE606B3" }, SecurityGroups: [ { "Fn::GetAtt": [ - "Ec2ClusterDefaultAutoScalingGroupInstanceSecurityGroup149B0A9E", + "EcsClusterDefaultAutoScalingGroupInstanceSecurityGroup912E1231", "GroupId" ] } @@ -55,7 +55,7 @@ export = { [ "#!/bin/bash\necho ECS_CLUSTER=", { - Ref: "Ec2ClusterEE43E89D" + Ref: "EcsCluster97242B84" }, // tslint:disable-next-line:max-line-length " >> /etc/ecs/ecs.config\nsudo iptables --insert FORWARD 1 --in-interface docker+ --destination 169.254.169.254/32 --jump DROP\nsudo service iptables save\necho ECS_AWSVPC_BLOCK_IMDS=true >> /etc/ecs/ecs.config" @@ -70,13 +70,13 @@ export = { MinSize: "0", DesiredCapacity: "1", LaunchConfigurationName: { - Ref: "Ec2ClusterDefaultAutoScalingGroupLaunchConfig7B2FED3A" + Ref: "EcsClusterDefaultAutoScalingGroupLaunchConfigB7E376C1" }, Tags: [ { Key: "Name", PropagateAtLaunch: true, - Value: "Ec2Cluster/DefaultAutoScalingGroup" + Value: "EcsCluster/DefaultAutoScalingGroup" } ], VPCZoneIdentifier: [ @@ -93,7 +93,7 @@ export = { })); expect(stack).to(haveResource("AWS::EC2::SecurityGroup", { - GroupDescription: "Ec2Cluster/DefaultAutoScalingGroup/InstanceSecurityGroup", + GroupDescription: "EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup", SecurityGroupEgress: [ { CidrIp: "0.0.0.0/0", @@ -105,7 +105,7 @@ export = { Tags: [ { Key: "Name", - Value: "Ec2Cluster/DefaultAutoScalingGroup" + Value: "EcsCluster/DefaultAutoScalingGroup" } ], VpcId: { @@ -161,7 +161,7 @@ export = { const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); cluster.addDefaultAutoScalingGroupCapacity({ instanceType: new InstanceType("m3.large") }); @@ -179,7 +179,7 @@ export = { const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {}); - const cluster = new ecs.Ec2Cluster(stack, 'Ec2Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'EcsCluster', { vpc }); cluster.addDefaultAutoScalingGroupCapacity({ instanceType: new ec2.InstanceType('t2.micro'), instanceCount: 3 diff --git a/packages/@aws-cdk/aws-ecs/test/test.l3s.ts b/packages/@aws-cdk/aws-ecs/test/test.l3s.ts index 57998d842358d..87d2f0e3a8a22 100644 --- a/packages/@aws-cdk/aws-ecs/test/test.l3s.ts +++ b/packages/@aws-cdk/aws-ecs/test/test.l3s.ts @@ -9,7 +9,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'VPC'); - const cluster = new ecs.Ec2Cluster(stack, 'Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'Cluster', { vpc }); // WHEN new ecs.LoadBalancedEc2Service(stack, 'Service', { @@ -28,7 +28,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.VpcNetwork(stack, 'VPC'); - const cluster = new ecs.FargateCluster(stack, 'Cluster', { vpc }); + const cluster = new ecs.EcsCluster(stack, 'Cluster', { vpc }); // WHEN new ecs.LoadBalancedFargateService(stack, 'Service', {