Skip to content

Commit 3d402f6

Browse files
committed
add back in stuff
1 parent 7442d16 commit 3d402f6

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

packages/cdk/nagSuppressions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ export const nagSuppressions = (stack: Stack) => {
102102
]
103103
)
104104

105+
safeAddNagSuppression(
106+
stack,
107+
"/VpcResourcesStack/S3Endpoint-tags/CustomResourcePolicy/Resource",
108+
[
109+
{
110+
id: "AwsSolutions-IAM5",
111+
reason: "Suppress error for wildcard permissions. This is fine here"
112+
}
113+
]
114+
)
115+
105116
}
106117

107118
const safeAddNagSuppression = (stack: Stack, path: string, suppressions: Array<NagPackSuppression>) => {

packages/cdk/stacks/VpcResourcesStack.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import {
1111
CfnSubnet,
1212
FlowLogDestination,
13-
GatewayVpcEndpointAwsService,
13+
GatewayVpcEndpoint,
1414
InterfaceVpcEndpoint,
1515
InterfaceVpcEndpointAwsService,
1616
IpAddresses,
@@ -97,19 +97,16 @@ export class VpcResourcesStack extends Stack {
9797

9898
this.vpc = vpc
9999

100-
// add vpc private endpoints - needed to set up ECR
100+
// add vpc private endpoints - needed to run ECS in private subnet
101+
// copied from https://stackoverflow.com/a/69578964/9294145
101102
this.addInterfaceEndpoint("ECRDockerEndpoint", InterfaceVpcEndpointAwsService.ECR_DOCKER)
102103
this.addInterfaceEndpoint("ECREndpoint", InterfaceVpcEndpointAwsService.ECR)
103104
this.addInterfaceEndpoint("SecretManagerEndpoint", InterfaceVpcEndpointAwsService.SECRETS_MANAGER)
104105
this.addInterfaceEndpoint("CloudWatchEndpoint", InterfaceVpcEndpointAwsService.CLOUDWATCH_MONITORING)
105106
this.addInterfaceEndpoint("CloudWatchLogsEndpoint", InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS)
106107
this.addInterfaceEndpoint("CloudWatchEventsEndpoint", InterfaceVpcEndpointAwsService.EVENTBRIDGE)
107108
this.addInterfaceEndpoint("SSMEndpoint", InterfaceVpcEndpointAwsService.SSM)
108-
109-
// add a gateway endpoint for S3
110-
vpc.addGatewayEndpoint("S3Endpoint", {
111-
service: GatewayVpcEndpointAwsService.S3
112-
})
109+
this.addGatewayEndpoint("S3Endpoint", InterfaceVpcEndpointAwsService.S3)
113110

114111
//Outputs
115112

@@ -154,10 +151,12 @@ export class VpcResourcesStack extends Stack {
154151
}
155152

156153
private addInterfaceEndpoint(name: string, awsService: InterfaceVpcEndpointAwsService): void {
157-
const endpoint: InterfaceVpcEndpoint = this.vpc.addInterfaceEndpoint(`${name}`, {
154+
const endpoint: InterfaceVpcEndpoint = this.vpc.addInterfaceEndpoint(name, {
158155
service: awsService
159156
})
160157

158+
// vpc endpoints do not support tagging from cdk/cloudformation
159+
// so use a custom resource to add them in
161160
new AwsCustomResource(this, `${name}-tags`, {
162161
installLatestAwsSdk: false,
163162
onUpdate: {
@@ -169,7 +168,7 @@ export class VpcResourcesStack extends Stack {
169168
Tags: [
170169
{
171170
Key: "Name",
172-
Value: `${this.stackName}-${name}-endpoint`
171+
Value: `${this.stackName}-${name}`
173172
}
174173
]
175174
},
@@ -183,4 +182,36 @@ export class VpcResourcesStack extends Stack {
183182

184183
endpoint.connections.allowFrom(Peer.ipv4(this.vpc.vpcCidrBlock), endpoint.connections.defaultPort!)
185184
}
185+
186+
private addGatewayEndpoint(name: string, awsService: InterfaceVpcEndpointAwsService): void {
187+
const endpoint: GatewayVpcEndpoint = this.vpc.addGatewayEndpoint(name, {
188+
service: awsService
189+
})
190+
191+
// vpc endpoints do not support tagging from cdk/cloudformation
192+
// so use a custom resource to add them in
193+
new AwsCustomResource(this, `${name}-tags`, {
194+
installLatestAwsSdk: false,
195+
onUpdate: {
196+
action: "createTags",
197+
parameters: {
198+
Resources: [
199+
endpoint.vpcEndpointId
200+
],
201+
Tags: [
202+
{
203+
Key: "Name",
204+
Value: `${this.stackName}-${name}`
205+
}
206+
]
207+
},
208+
physicalResourceId: PhysicalResourceId.of(Date.now().toString()),
209+
service: "EC2"
210+
},
211+
policy: AwsCustomResourcePolicy.fromSdkCalls({
212+
resources: AwsCustomResourcePolicy.ANY_RESOURCE
213+
})
214+
})
215+
}
216+
186217
}

0 commit comments

Comments
 (0)