Skip to content

Commit caa0077

Browse files
piradeepkrix0rrr
authored andcommitted
feat(ecs-patterns): support propagateTags and ecsManagedTags (#4100)
Add propagateTaskTagsFrom and EcsManagedTags properties to constructs in ecs-patterns. Deprecate `propagateTaskTagsFrom` in favor of `propagateTags` everywhere. Addresses: #3979
1 parent 27d209d commit caa0077

12 files changed

+107
-10
lines changed

packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DnsValidatedCertificate, ICertificate } from '@aws-cdk/aws-certificatemanager';
22
import { IVpc } from '@aws-cdk/aws-ec2';
3-
import { AwsLogDriver, BaseService, Cluster, ContainerImage, ICluster, LogDriver, Secret } from '@aws-cdk/aws-ecs';
3+
import { AwsLogDriver, BaseService, Cluster, ContainerImage, ICluster, LogDriver, PropagatedTagSource, Secret } from '@aws-cdk/aws-ecs';
44
import { ApplicationListener, ApplicationLoadBalancer, ApplicationProtocol, ApplicationTargetGroup } from '@aws-cdk/aws-elasticloadbalancingv2';
55
import { IRole } from '@aws-cdk/aws-iam';
66
import { AddressRecordTarget, ARecord, IHostedZone } from '@aws-cdk/aws-route53';
@@ -161,6 +161,21 @@ export interface ApplicationLoadBalancedServiceBaseProps {
161161
*/
162162
readonly healthCheckGracePeriod?: cdk.Duration;
163163

164+
/**
165+
* Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
166+
* Tags can only be propagated to the tasks within the service during service creation.
167+
*
168+
* @default - none
169+
*/
170+
readonly propagateTags?: PropagatedTagSource;
171+
172+
/**
173+
* Specifies whether to enable Amazon ECS managed tags for the tasks within the service. For more information, see
174+
* [Tagging Your Amazon ECS Resources](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html)
175+
*
176+
* @default false
177+
*/
178+
readonly enableECSManagedTags?: boolean;
164179
}
165180

166181
/**

packages/@aws-cdk/aws-ecs-patterns/lib/base/network-load-balanced-service-base.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IVpc } from '@aws-cdk/aws-ec2';
2-
import { AwsLogDriver, BaseService, Cluster, ContainerImage, ICluster, LogDriver, Secret } from '@aws-cdk/aws-ecs';
2+
import { AwsLogDriver, BaseService, Cluster, ContainerImage, ICluster, LogDriver, PropagatedTagSource, Secret } from '@aws-cdk/aws-ecs';
33
import { NetworkListener, NetworkLoadBalancer, NetworkTargetGroup } from '@aws-cdk/aws-elasticloadbalancingv2';
44
import { IRole } from '@aws-cdk/aws-iam';
55
import { AddressRecordTarget, ARecord, IHostedZone } from '@aws-cdk/aws-route53';
@@ -139,6 +139,21 @@ export interface NetworkLoadBalancedServiceBaseProps {
139139
*/
140140
readonly healthCheckGracePeriod?: cdk.Duration;
141141

142+
/**
143+
* Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
144+
* Tags can only be propagated to the tasks within the service during service creation.
145+
*
146+
* @default - none
147+
*/
148+
readonly propagateTags?: PropagatedTagSource;
149+
150+
/**
151+
* Specifies whether to enable Amazon ECS managed tags for the tasks within the service. For more information, see
152+
* [Tagging Your Amazon ECS Resources](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html)
153+
*
154+
* @default false
155+
*/
156+
readonly enableECSManagedTags?: boolean;
142157
}
143158

144159
/**

packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ScalingInterval } from '@aws-cdk/aws-applicationautoscaling';
22
import { IVpc } from '@aws-cdk/aws-ec2';
3-
import { AwsLogDriver, BaseService, Cluster, ContainerImage, ICluster, LogDriver, Secret } from '@aws-cdk/aws-ecs';
3+
import { AwsLogDriver, BaseService, Cluster, ContainerImage, ICluster, LogDriver, PropagatedTagSource, Secret } from '@aws-cdk/aws-ecs';
44
import { IQueue, Queue } from '@aws-cdk/aws-sqs';
55
import { CfnOutput, Construct, Stack } from '@aws-cdk/core';
66

@@ -102,6 +102,22 @@ export interface QueueProcessingServiceBaseProps {
102102
* @default - AwsLogDriver if enableLogging is true
103103
*/
104104
readonly logDriver?: LogDriver;
105+
106+
/**
107+
* Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
108+
* Tags can only be propagated to the tasks within the service during service creation.
109+
*
110+
* @default - none
111+
*/
112+
readonly propagateTags?: PropagatedTagSource;
113+
114+
/**
115+
* Specifies whether to enable Amazon ECS managed tags for the tasks within the service. For more information, see
116+
* [Tagging Your Amazon ECS Resources](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html)
117+
*
118+
* @default false
119+
*/
120+
readonly enableECSManagedTags?: boolean;
105121
}
106122

107123
/**

packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
100100
assignPublicIp: false,
101101
serviceName: props.serviceName,
102102
healthCheckGracePeriod: props.healthCheckGracePeriod,
103+
propagateTags: props.propagateTags,
104+
enableECSManagedTags: props.enableECSManagedTags,
103105
});
104106
this.addServiceAsTarget(this.service);
105107
}

packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
100100
assignPublicIp: false,
101101
serviceName: props.serviceName,
102102
healthCheckGracePeriod: props.healthCheckGracePeriod,
103+
propagateTags: props.propagateTags,
104+
enableECSManagedTags: props.enableECSManagedTags,
103105
});
104106
this.addServiceAsTarget(this.service);
105107
}

packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export class QueueProcessingEc2Service extends QueueProcessingServiceBase {
9292
this.service = new Ec2Service(this, 'QueueProcessingService', {
9393
cluster: this.cluster,
9494
desiredCount: this.desiredCount,
95-
taskDefinition: this.taskDefinition
95+
taskDefinition: this.taskDefinition,
96+
propagateTags: props.propagateTags,
97+
enableECSManagedTags: props.enableECSManagedTags,
9698
});
9799
this.configureAutoscalingForService(this.service);
98100
}

packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
109109
assignPublicIp: this.assignPublicIp,
110110
serviceName: props.serviceName,
111111
healthCheckGracePeriod: props.healthCheckGracePeriod,
112+
propagateTags: props.propagateTags,
113+
enableECSManagedTags: props.enableECSManagedTags,
112114
});
113115
this.addServiceAsTarget(this.service);
114116
}

packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
105105
assignPublicIp: this.assignPublicIp,
106106
serviceName: props.serviceName,
107107
healthCheckGracePeriod: props.healthCheckGracePeriod,
108+
propagateTags: props.propagateTags,
109+
enableECSManagedTags: props.enableECSManagedTags,
108110
});
109111
this.addServiceAsTarget(this.service);
110112
}

packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
8787
this.service = new FargateService(this, 'QueueProcessingFargateService', {
8888
cluster: this.cluster,
8989
desiredCount: this.desiredCount,
90-
taskDefinition: this.taskDefinition
90+
taskDefinition: this.taskDefinition,
91+
propagateTags: props.propagateTags,
92+
enableECSManagedTags: props.enableECSManagedTags,
9193
});
9294
this.configureAutoscalingForService(this.service);
9395
}

packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export interface Ec2ServiceProps extends BaseServiceOptions {
7474
* Specifies whether to propagate the tags from the task definition or the service to the tasks in the service.
7575
* Tags can only be propagated to the tasks within the service during service creation.
7676
*
77-
* @default PropagatedTagSource.SERVICE
77+
* @deprecated Use `propagateTags` instead.
78+
* @default PropagatedTagSource.NONE
7879
*/
7980
readonly propagateTaskTagsFrom?: PropagatedTagSource;
8081
}
@@ -127,14 +128,21 @@ export class Ec2Service extends BaseService implements IEc2Service {
127128
throw new Error('Supplied TaskDefinition is not configured for compatibility with EC2');
128129
}
129130

131+
if (props.propagateTags && props.propagateTaskTagsFrom) {
132+
throw new Error('You can only specify either propagateTags or propagateTaskTagsFrom. Alternatively, you can leave both blank');
133+
}
134+
135+
const propagateTagsFromSource = props.propagateTaskTagsFrom !== undefined ? props.propagateTaskTagsFrom
136+
: (props.propagateTags !== undefined ? props.propagateTags : PropagatedTagSource.NONE);
137+
130138
super(scope, id, {
131139
...props,
132140
// If daemon, desiredCount must be undefined and that's what we want. Otherwise, default to 1.
133141
desiredCount: props.daemon || props.desiredCount !== undefined ? props.desiredCount : 1,
134142
maxHealthyPercent: props.daemon && props.maxHealthyPercent === undefined ? 100 : props.maxHealthyPercent,
135143
minHealthyPercent: props.daemon && props.minHealthyPercent === undefined ? 0 : props.minHealthyPercent,
136144
launchType: LaunchType.EC2,
137-
propagateTags: props.propagateTaskTagsFrom === undefined ? PropagatedTagSource.NONE : props.propagateTaskTagsFrom,
145+
propagateTags: propagateTagsFromSource,
138146
enableECSManagedTags: props.enableECSManagedTags,
139147
},
140148
{

0 commit comments

Comments
 (0)