Skip to content

Commit 692a0d0

Browse files
authored
fix(route53): fix cross account delegation deployment dependency (#19047)
For each zone to delegate a policy is created and attached to the handler role. This change adds an explicit dependency between the policy attachment and the lambda handler to make sure the cross account delegation handler is not started before the policy is created and attached to the handler role. fixes: #19041 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 171fdcd commit 692a0d0

File tree

3 files changed

+49
-34
lines changed

3 files changed

+49
-34
lines changed

packages/@aws-cdk/aws-route53/lib/record-set.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,13 @@ export class CrossAccountZoneDelegationRecord extends CoreConstruct {
690690

691691
const role = iam.Role.fromRoleArn(this, 'cross-account-zone-delegation-handler-role', provider.roleArn);
692692

693-
role.addToPrincipalPolicy(new iam.PolicyStatement({
693+
const addToPrinciplePolicyResult = role.addToPrincipalPolicy(new iam.PolicyStatement({
694694
effect: iam.Effect.ALLOW,
695695
actions: ['sts:AssumeRole'],
696696
resources: [props.delegationRole.roleArn],
697697
}));
698698

699-
new CustomResource(this, 'CrossAccountZoneDelegationCustomResource', {
699+
const customResource = new CustomResource(this, 'CrossAccountZoneDelegationCustomResource', {
700700
resourceType: CROSS_ACCOUNT_ZONE_DELEGATION_RESOURCE_TYPE,
701701
serviceToken: provider.serviceToken,
702702
removalPolicy: props.removalPolicy,
@@ -709,5 +709,9 @@ export class CrossAccountZoneDelegationRecord extends CoreConstruct {
709709
TTL: (props.ttl || Duration.days(2)).toSeconds(),
710710
},
711711
});
712+
713+
if (addToPrinciplePolicyResult.policyDependable) {
714+
customResource.node.addDependency(addToPrinciplePolicyResult.policyDependable);
715+
}
712716
}
713717
}

packages/@aws-cdk/aws-route53/test/integ.cross-account-zone-delegation.expected.json

+15-9
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
},
155155
"TTL": 172800
156156
},
157+
"DependsOn": [
158+
"DelegationWithZoneIdcrossaccountzonedelegationhandlerrolePolicy5170A69B"
159+
],
157160
"UpdateReplacePolicy": "Delete",
158161
"DeletionPolicy": "Delete"
159162
},
@@ -184,7 +187,7 @@
184187
"Properties": {
185188
"Code": {
186189
"S3Bucket": {
187-
"Ref": "AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3Bucket200D9216"
190+
"Ref": "AssetParameters7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8aS3BucketC1366C27"
188191
},
189192
"S3Key": {
190193
"Fn::Join": [
@@ -197,7 +200,7 @@
197200
"Fn::Split": [
198201
"||",
199202
{
200-
"Ref": "AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3VersionKey0E5C26F0"
203+
"Ref": "AssetParameters7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8aS3VersionKeyEE72CEF8"
201204
}
202205
]
203206
}
@@ -210,7 +213,7 @@
210213
"Fn::Split": [
211214
"||",
212215
{
213-
"Ref": "AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3VersionKey0E5C26F0"
216+
"Ref": "AssetParameters7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8aS3VersionKeyEE72CEF8"
214217
}
215218
]
216219
}
@@ -315,22 +318,25 @@
315318
},
316319
"TTL": 172800
317320
},
321+
"DependsOn": [
322+
"DelegationWithZoneNamecrossaccountzonedelegationhandlerrolePolicy86996882"
323+
],
318324
"UpdateReplacePolicy": "Delete",
319325
"DeletionPolicy": "Delete"
320326
}
321327
},
322328
"Parameters": {
323-
"AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3Bucket200D9216": {
329+
"AssetParameters7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8aS3BucketC1366C27": {
324330
"Type": "String",
325-
"Description": "S3 bucket for asset \"d17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602\""
331+
"Description": "S3 bucket for asset \"7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8a\""
326332
},
327-
"AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3VersionKey0E5C26F0": {
333+
"AssetParameters7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8aS3VersionKeyEE72CEF8": {
328334
"Type": "String",
329-
"Description": "S3 key for asset version \"d17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602\""
335+
"Description": "S3 key for asset version \"7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8a\""
330336
},
331-
"AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602ArtifactHash37FB4D0C": {
337+
"AssetParameters7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8aArtifactHashAADF3168": {
332338
"Type": "String",
333-
"Description": "Artifact hash for asset \"d17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602\""
339+
"Description": "Artifact hash for asset \"7625bcc3bbd65c490a92d42790a563e31dc02c18006ef272338c8c788849bb8a\""
334340
}
335341
}
336342
}

packages/@aws-cdk/aws-route53/test/record-set.test.ts

+28-23
Original file line numberDiff line numberDiff line change
@@ -737,33 +737,38 @@ describe('record set', () => {
737737

738738
// THEN
739739
const childHostedZones = [
740-
{ name: 'sub.myzone.com', id: 'ChildHostedZone4B14AC71' },
741-
{ name: 'anothersub.myzone.com', id: 'ChildHostedZone2A37198F0' },
740+
{ name: 'sub.myzone.com', id: 'ChildHostedZone4B14AC71', dependsOn: 'DelegationcrossaccountzonedelegationhandlerrolePolicy1E157602' },
741+
{ name: 'anothersub.myzone.com', id: 'ChildHostedZone2A37198F0', dependsOn: 'Delegation2crossaccountzonedelegationhandlerrolePolicy713BEAC3' },
742742
];
743743

744744
for (var childHostedZone of childHostedZones) {
745-
Template.fromStack(stack).hasResourceProperties('Custom::CrossAccountZoneDelegation', {
746-
ServiceToken: {
747-
'Fn::GetAtt': [
748-
'CustomCrossAccountZoneDelegationCustomResourceProviderHandler44A84265',
749-
'Arn',
750-
],
751-
},
752-
AssumeRoleArn: {
753-
'Fn::GetAtt': [
754-
'ParentHostedZoneCrossAccountZoneDelegationRole95B1C36E',
755-
'Arn',
756-
],
757-
},
758-
ParentZoneName: 'myzone.com',
759-
DelegatedZoneName: childHostedZone.name,
760-
DelegatedZoneNameServers: {
761-
'Fn::GetAtt': [
762-
childHostedZone.id,
763-
'NameServers',
764-
],
745+
Template.fromStack(stack).hasResource('Custom::CrossAccountZoneDelegation', {
746+
Properties: {
747+
ServiceToken: {
748+
'Fn::GetAtt': [
749+
'CustomCrossAccountZoneDelegationCustomResourceProviderHandler44A84265',
750+
'Arn',
751+
],
752+
},
753+
AssumeRoleArn: {
754+
'Fn::GetAtt': [
755+
'ParentHostedZoneCrossAccountZoneDelegationRole95B1C36E',
756+
'Arn',
757+
],
758+
},
759+
ParentZoneName: 'myzone.com',
760+
DelegatedZoneName: childHostedZone.name,
761+
DelegatedZoneNameServers: {
762+
'Fn::GetAtt': [
763+
childHostedZone.id,
764+
'NameServers',
765+
],
766+
},
767+
TTL: 60,
765768
},
766-
TTL: 60,
769+
DependsOn: [
770+
childHostedZone.dependsOn,
771+
],
767772
});
768773
}
769774
});

0 commit comments

Comments
 (0)