Skip to content

Commit be9b11a

Browse files
authored
fix for tgw peering multiple attachments issue (#1237)
* tgw construct id update * add console logs * initialize static class var * remove debug console logs
1 parent d961589 commit be9b11a

File tree

2 files changed

+15
-2
lines changed
  • src/lib/custom-resources
    • cdk-transit-gateway-accept-peering/cdk
    • cdk-transit-gateway-create-peering/cdk

2 files changed

+15
-2
lines changed

src/lib/custom-resources/cdk-transit-gateway-accept-peering/cdk/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ export interface TransitGatewayAcceptPeeringAttachmentProps {
3131
export class TransitGatewayAcceptPeeringAttachment extends Construct {
3232
private readonly resource: cdk.CustomResource;
3333
private readonly role: iam.IRole;
34+
private static attachmentCount: number = 0;
3435

3536
constructor(scope: Construct, id: string, props: TransitGatewayAcceptPeeringAttachmentProps) {
3637
super(scope, id);
3738

38-
this.role = iam.Role.fromRoleArn(scope, `${resourceType}Role`, props.roleArn);
39+
const roleConstructId =
40+
++TransitGatewayAcceptPeeringAttachment.attachmentCount > 1
41+
? `${resourceType}Role${TransitGatewayAcceptPeeringAttachment.attachmentCount}`
42+
: `${resourceType}Role`;
43+
44+
this.role = iam.Role.fromRoleArn(scope, roleConstructId, props.roleArn);
3945

4046
this.resource = new cdk.CustomResource(this, 'Resource', {
4147
resourceType,

src/lib/custom-resources/cdk-transit-gateway-create-peering/cdk/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ export interface TransitGatewayCreatePeeringAttachmentProps {
3434
export class TransitGatewayCreatePeeringAttachment extends Construct {
3535
private readonly resource: cdk.CustomResource;
3636
private readonly role: iam.IRole;
37+
private static attachmentCount: number = 0;
3738

3839
constructor(scope: Construct, id: string, props: TransitGatewayCreatePeeringAttachmentProps) {
3940
super(scope, id);
4041

4142
const { transitGatewayId, targetTransitGatewayId, targetAccountId, targetRegion, tagValue } = props;
42-
this.role = iam.Role.fromRoleArn(scope, `${resourceType}Role`, props.roleArn);
43+
44+
const roleConstructId =
45+
++TransitGatewayCreatePeeringAttachment.attachmentCount > 1
46+
? `${resourceType}Role${TransitGatewayCreatePeeringAttachment.attachmentCount}`
47+
: `${resourceType}Role`;
48+
49+
this.role = iam.Role.fromRoleArn(scope, roleConstructId, props.roleArn);
4350

4451
this.resource = new cdk.CustomResource(this, 'Resource', {
4552
resourceType,

0 commit comments

Comments
 (0)