@@ -14,6 +14,7 @@ import {
1414 InterfaceVpcEndpoint ,
1515 InterfaceVpcEndpointAwsService ,
1616 IpAddresses ,
17+ IVpcEndpoint ,
1718 Peer ,
1819 Vpc
1920} from "aws-cdk-lib/aws-ec2"
@@ -154,31 +155,7 @@ export class VpcResourcesStack extends Stack {
154155 const endpoint : InterfaceVpcEndpoint = this . vpc . addInterfaceEndpoint ( name , {
155156 service : awsService
156157 } )
157-
158- // vpc endpoints do not support tagging from cdk/cloudformation
159- // so use a custom resource to add them in
160- new AwsCustomResource ( this , `${ name } -tags` , {
161- installLatestAwsSdk : false ,
162- onUpdate : {
163- action : "createTags" ,
164- parameters : {
165- Resources : [
166- endpoint . vpcEndpointId
167- ] ,
168- Tags : [
169- {
170- Key : "Name" ,
171- Value : `${ this . stackName } -${ name } `
172- }
173- ]
174- } ,
175- physicalResourceId : PhysicalResourceId . of ( Date . now ( ) . toString ( ) ) ,
176- service : "EC2"
177- } ,
178- policy : AwsCustomResourcePolicy . fromSdkCalls ( {
179- resources : AwsCustomResourcePolicy . ANY_RESOURCE
180- } )
181- } )
158+ this . addEndpointTag ( name , endpoint )
182159
183160 endpoint . connections . allowFrom ( Peer . ipv4 ( this . vpc . vpcCidrBlock ) , endpoint . connections . defaultPort ! )
184161 }
@@ -187,7 +164,10 @@ export class VpcResourcesStack extends Stack {
187164 const endpoint : GatewayVpcEndpoint = this . vpc . addGatewayEndpoint ( name , {
188165 service : awsService
189166 } )
167+ this . addEndpointTag ( name , endpoint )
168+ }
190169
170+ private addEndpointTag ( name : string , endpoint : IVpcEndpoint ) {
191171 // vpc endpoints do not support tagging from cdk/cloudformation
192172 // so use a custom resource to add them in
193173 new AwsCustomResource ( this , `${ name } -tags` , {
@@ -212,6 +192,7 @@ export class VpcResourcesStack extends Stack {
212192 resources : AwsCustomResourcePolicy . ANY_RESOURCE
213193 } )
214194 } )
195+
215196 }
216197
217198}
0 commit comments