Skip to content

Commit 8eee0e9

Browse files
committed
Always replace on update
1 parent 3177d2e commit 8eee0e9

3 files changed

Lines changed: 2 additions & 190 deletions

File tree

packages/cdk-blue-green-container-deployment/src/__tests__/__snapshots__/dummy-task-definition.test.ts.snap

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -60,164 +60,6 @@ Object {
6060
Object {
6161
"Action": Array [
6262
"ecs:RegisterTaskDefinition",
63-
"ecs:DescribeTaskDefinition",
64-
"ecs:DeregisterTaskDefinition",
65-
],
66-
"Effect": "Allow",
67-
"Resource": "*",
68-
},
69-
Object {
70-
"Action": "iam:PassRole",
71-
"Effect": "Allow",
72-
"Resource": Object {
73-
"Fn::GetAtt": Array [
74-
"DummyTaskDefinitionExecutionRole715DBD43",
75-
"Arn",
76-
],
77-
},
78-
},
79-
],
80-
"Version": "2012-10-17",
81-
},
82-
"PolicyName": "DummyTaskDefinitionCustomResourcePolicyB5660701",
83-
"Roles": Array [
84-
Object {
85-
"Ref": "AWS679f53fac002430cb0da5b7982bd2287ServiceRoleC1EA0FF2",
86-
},
87-
],
88-
},
89-
"Type": "AWS::IAM::Policy",
90-
},
91-
"DummyTaskDefinitionE3D9D432": Object {
92-
"DeletionPolicy": "Delete",
93-
"DependsOn": Array [
94-
"DummyTaskDefinitionCustomResourcePolicyB5660701",
95-
],
96-
"Properties": Object {
97-
"Create": Object {
98-
"Fn::Join": Array [
99-
"",
100-
Array [
101-
"{\\"service\\":\\"ECS\\",\\"action\\":\\"registerTaskDefinition\\",\\"parameters\\":{\\"requiresCompatibilities\\":[\\"FARGATE\\"],\\"family\\":\\"c86e1e5d419d3c124c7e40411b7e7805f91621e162\\",\\"executionRoleArn\\":\\"",
102-
Object {
103-
"Fn::GetAtt": Array [
104-
"DummyTaskDefinitionExecutionRole715DBD43",
105-
"Arn",
106-
],
107-
},
108-
"\\",\\"networkMode\\":\\"awsvpc\\",\\"cpu\\":\\"256\\",\\"memory\\":\\"512\\",\\"containerDefinitions\\":[{\\"name\\":\\"sample-website\\",\\"image\\":\\"image\\",\\"portMappings\\":[{\\"hostPort\\":80,\\"protocol\\":\\"tcp\\",\\"containerPort\\":80}]}]},\\"physicalResourceId\\":{\\"responsePath\\":\\"taskDefinition.taskDefinitionArn\\"}}",
109-
],
110-
],
111-
},
112-
"Delete": "{\\"service\\":\\"ECS\\",\\"action\\":\\"deregisterTaskDefinition\\",\\"parameters\\":{\\"taskDefinition\\":\\"PHYSICAL:RESOURCEID:\\"}}",
113-
"InstallLatestAwsSdk": true,
114-
"ServiceToken": Object {
115-
"Fn::GetAtt": Array [
116-
"AWS679f53fac002430cb0da5b7982bd22872D164C4C",
117-
"Arn",
118-
],
119-
},
120-
"Update": "{\\"service\\":\\"ECS\\",\\"action\\":\\"describeTaskDefinition\\",\\"parameters\\":{\\"taskDefinition\\":\\"PHYSICAL:RESOURCEID:\\"},\\"physicalResourceId\\":{\\"responsePath\\":\\"taskDefinition.taskDefinitionArn\\"}}",
121-
},
122-
"Type": "Custom::DummyTaskDefinition",
123-
"UpdateReplacePolicy": "Delete",
124-
},
125-
"DummyTaskDefinitionExecutionRole715DBD43": Object {
126-
"Properties": Object {
127-
"AssumeRolePolicyDocument": Object {
128-
"Statement": Array [
129-
Object {
130-
"Action": "sts:AssumeRole",
131-
"Effect": "Allow",
132-
"Principal": Object {
133-
"Service": "ecs-tasks.amazonaws.com",
134-
},
135-
},
136-
],
137-
"Version": "2012-10-17",
138-
},
139-
"ManagedPolicyArns": Array [
140-
Object {
141-
"Fn::Join": Array [
142-
"",
143-
Array [
144-
"arn:",
145-
Object {
146-
"Ref": "AWS::Partition",
147-
},
148-
":iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy",
149-
],
150-
],
151-
},
152-
],
153-
},
154-
"Type": "AWS::IAM::Role",
155-
},
156-
},
157-
}
158-
`;
159-
160-
exports[`with updates allowed 1`] = `
161-
Object {
162-
"Parameters": Any<Object>,
163-
"Resources": Object {
164-
"AWS679f53fac002430cb0da5b7982bd22872D164C4C": Object {
165-
"DependsOn": Array [
166-
"AWS679f53fac002430cb0da5b7982bd2287ServiceRoleC1EA0FF2",
167-
],
168-
"Properties": Object {
169-
"Code": Any<Object>,
170-
"Handler": "index.handler",
171-
"Role": Object {
172-
"Fn::GetAtt": Array [
173-
"AWS679f53fac002430cb0da5b7982bd2287ServiceRoleC1EA0FF2",
174-
"Arn",
175-
],
176-
},
177-
"Runtime": "nodejs12.x",
178-
"Timeout": 120,
179-
},
180-
"Type": "AWS::Lambda::Function",
181-
},
182-
"AWS679f53fac002430cb0da5b7982bd2287ServiceRoleC1EA0FF2": Object {
183-
"Properties": Object {
184-
"AssumeRolePolicyDocument": Object {
185-
"Statement": Array [
186-
Object {
187-
"Action": "sts:AssumeRole",
188-
"Effect": "Allow",
189-
"Principal": Object {
190-
"Service": "lambda.amazonaws.com",
191-
},
192-
},
193-
],
194-
"Version": "2012-10-17",
195-
},
196-
"ManagedPolicyArns": Array [
197-
Object {
198-
"Fn::Join": Array [
199-
"",
200-
Array [
201-
"arn:",
202-
Object {
203-
"Ref": "AWS::Partition",
204-
},
205-
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
206-
],
207-
],
208-
},
209-
],
210-
},
211-
"Type": "AWS::IAM::Role",
212-
},
213-
"DummyTaskDefinitionCustomResourcePolicyB5660701": Object {
214-
"Properties": Object {
215-
"PolicyDocument": Object {
216-
"Statement": Array [
217-
Object {
218-
"Action": Array [
219-
"ecs:RegisterTaskDefinition",
220-
"ecs:DescribeTaskDefinition",
22163
"ecs:DeregisterTaskDefinition",
22264
],
22365
"Effect": "Allow",

packages/cdk-blue-green-container-deployment/src/__tests__/dummy-task-definition.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,3 @@ test('default setup', (): void => {
1414
ignoreAssets: true,
1515
});
1616
});
17-
18-
test('with updates allowed', (): void => {
19-
const stack = new Stack();
20-
21-
new DummyTaskDefinition(stack, 'DummyTaskDefinition', {
22-
image: 'image',
23-
allowUpdates: true,
24-
});
25-
26-
expect(stack).toMatchCdkSnapshot({
27-
ignoreAssets: true,
28-
});
29-
});

packages/cdk-blue-green-container-deployment/src/dummy-task-definition.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ export interface DummyTaskDefinitionProps {
3838
* @default 80
3939
*/
4040
readonly containerPort?: number;
41-
42-
/**
43-
* Allow task definition to be updated, causing new task definition to be created with new attributes.
44-
* Updates could negatively affect blue/green deployments.
45-
* @default false
46-
*/
47-
readonly allowUpdates?: boolean;
4841
}
4942

5043
export class DummyTaskDefinition extends Construct implements IDummyTaskDefinition {
@@ -69,7 +62,6 @@ export class DummyTaskDefinition extends Construct implements IDummyTaskDefiniti
6962
this.family = props.family ?? this.node.addr;
7063
this.containerName = props.containerName ?? 'sample-website';
7164
this.containerPort = props.containerPort ?? 80;
72-
const allowUpdates = !!props.allowUpdates;
7365

7466
const registerTaskDefinition: AwsSdkCall = {
7567
service: 'ECS',
@@ -98,15 +90,6 @@ export class DummyTaskDefinition extends Construct implements IDummyTaskDefiniti
9890
physicalResourceId: PhysicalResourceId.fromResponse('taskDefinition.taskDefinitionArn'),
9991
};
10092

101-
const describeTaskDefinition: AwsSdkCall = {
102-
service: 'ECS',
103-
action: 'describeTaskDefinition',
104-
parameters: {
105-
taskDefinition: new PhysicalResourceIdReference(),
106-
},
107-
physicalResourceId: PhysicalResourceId.fromResponse('taskDefinition.taskDefinitionArn'),
108-
};
109-
11093
const deregisterTaskDefinition: AwsSdkCall = {
11194
service: 'ECS',
11295
action: 'deregisterTaskDefinition',
@@ -118,12 +101,12 @@ export class DummyTaskDefinition extends Construct implements IDummyTaskDefiniti
118101
const taskDefinition = new AwsCustomResource(this, 'DummyTaskDefinition', {
119102
resourceType: 'Custom::DummyTaskDefinition',
120103
onCreate: registerTaskDefinition,
121-
onUpdate: allowUpdates ? registerTaskDefinition : describeTaskDefinition,
104+
onUpdate: registerTaskDefinition,
122105
onDelete: deregisterTaskDefinition,
123106
policy: AwsCustomResourcePolicy.fromStatements([
124107
new PolicyStatement({
125108
effect: Effect.ALLOW,
126-
actions: ['ecs:RegisterTaskDefinition', 'ecs:DescribeTaskDefinition', 'ecs:DeregisterTaskDefinition'],
109+
actions: ['ecs:RegisterTaskDefinition', 'ecs:DeregisterTaskDefinition'],
127110
resources: ['*'],
128111
}),
129112
new PolicyStatement({

0 commit comments

Comments
 (0)