-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(events-targets): Add tagging for ECS tasks triggered by an event #23838
Changes from 4 commits
680dcc5
66dc94e
20b1ddc
9395fd0
7230673
d3fe4bd
0b0644f
652373d
c012487
81c729e
acf5cf2
ab72e36
58e31cc
373ada2
f509634
b55edb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,20 @@ import { Construct } from 'constructs'; | |
import { ContainerOverride } from './ecs-task-properties'; | ||
import { addToDeadLetterQueueResourcePolicy, bindBaseTargetConfig, singletonEventRole, TargetBaseProps } from './util'; | ||
|
||
/** | ||
* Tag | ||
*/ | ||
export interface Tag { | ||
|
||
/** | ||
* key to e tagged | ||
*/ | ||
readonly key: string; | ||
/** | ||
* additional value | ||
*/ | ||
readonly value: string; | ||
} | ||
/** | ||
* Properties to define an ECS Event Task | ||
*/ | ||
|
@@ -81,6 +95,20 @@ export interface EcsTaskProps extends TargetBaseProps { | |
* @default - ECS will set the Fargate platform version to 'LATEST' | ||
*/ | ||
readonly platformVersion?: ecs.FargatePlatformVersion; | ||
|
||
/** | ||
* Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. | ||
* | ||
* @default - Tags will not be propagated | ||
*/ | ||
readonly propagateTags?: boolean | ||
|
||
/** | ||
* The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define. | ||
* | ||
* @default - No tags are applied to the task | ||
*/ | ||
readonly tagList?: Tag[] | ||
} | ||
|
||
/** | ||
|
@@ -108,6 +136,8 @@ export class EcsTask implements events.IRuleTarget { | |
private readonly taskCount: number; | ||
private readonly role: iam.IRole; | ||
private readonly platformVersion?: ecs.FargatePlatformVersion; | ||
private readonly propagateTags?: ecs.PropagatedTagSource; | ||
private readonly tagList?: Tag[] | ||
|
||
constructor(private readonly props: EcsTaskProps) { | ||
if (props.securityGroup !== undefined && props.securityGroups !== undefined) { | ||
|
@@ -118,12 +148,17 @@ export class EcsTask implements events.IRuleTarget { | |
this.taskDefinition = props.taskDefinition; | ||
this.taskCount = props.taskCount ?? 1; | ||
this.platformVersion = props.platformVersion; | ||
this.propagateTags = props.propagateTags === true ? ecs.PropagatedTagSource.TASK_DEFINITION : undefined ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is giving me pause. If CloudFormation expects something other than a true or false here, I think we're potentially setting ourselves up for breaking changes if they ever add more allowed values here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see how this could become problematic even though this is the only allowed value today. I can update this so it takes a value of type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated! |
||
|
||
this.role = props.role ?? singletonEventRole(this.taskDefinition); | ||
for (const stmt of this.createEventRolePolicyStatements()) { | ||
this.role.addToPrincipalPolicy(stmt); | ||
} | ||
|
||
if (props.tagList) { | ||
this.tagList = props.tagList; | ||
} | ||
|
||
// Security groups are only configurable with the "awsvpc" network mode. | ||
if (this.taskDefinition.networkMode !== ecs.NetworkMode.AWS_VPC) { | ||
if (props.securityGroup !== undefined || props.securityGroups !== undefined) { | ||
|
@@ -159,11 +194,13 @@ export class EcsTask implements events.IRuleTarget { | |
const input = { containerOverrides }; | ||
const taskCount = this.taskCount; | ||
const taskDefinitionArn = this.taskDefinition.taskDefinitionArn; | ||
const propagateTags = this.propagateTags; | ||
const tagList = this.tagList; | ||
|
||
const subnetSelection = this.props.subnetSelection || { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }; | ||
const assignPublicIp = subnetSelection.subnetType === ec2.SubnetType.PUBLIC ? 'ENABLED' : 'DISABLED'; | ||
|
||
const baseEcsParameters = { taskCount, taskDefinitionArn }; | ||
const baseEcsParameters = { taskCount, taskDefinitionArn, propagateTags, tagList }; | ||
|
||
const ecsParameters: events.CfnRule.EcsParametersProperty = this.taskDefinition.networkMode === ecs.NetworkMode.AWS_VPC | ||
? { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"20.0.0"} | ||
{"version":"29.0.0"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "21.0.0", | ||
"version": "29.0.0", | ||
"testCases": { | ||
"EcsTest/DefaultTest": { | ||
"stacks": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up to reviewers: these updates that aren't specifically related to ECS were required because they would not compile when running Rosetta.