Skip to content

Commit 61ec526

Browse files
committed
feat: add integ test
1 parent 1b184a2 commit 61ec526

2 files changed

Lines changed: 78 additions & 3 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as integ from '@aws-cdk/integ-tests-alpha';
2+
import * as cdk from 'aws-cdk-lib';
3+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
4+
import * as ecs from 'aws-cdk-lib/aws-ecs';
5+
import * as iam from 'aws-cdk-lib/aws-iam';
6+
import * as kms from 'aws-cdk-lib/aws-kms';
7+
import * as acm from 'aws-cdk-lib/aws-acmpca';
8+
9+
const app = new cdk.App();
10+
const stack = new cdk.Stack(app, 'aws-ecs-integ');
11+
const vpc = new ec2.Vpc(stack, 'Vpc');
12+
const cluster = new ecs.Cluster(stack, 'EcsCluster', {
13+
vpc,
14+
defaultCloudMapNamespace: {
15+
name: 'api.com',
16+
useForServiceConnect: true,
17+
},
18+
});
19+
20+
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef');
21+
22+
const ca = acm.CertificateAuthority.fromCertificateAuthorityArn(stack, 'CA',
23+
'arn:aws:acm-pca:us-east-1:1234567890:certificate-authority/xxxxxx',
24+
);
25+
26+
const kmsKey = new kms.Key(stack, 'KmsKey', {
27+
enableKeyRotation: true,
28+
});
29+
kmsKey.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY);
30+
31+
taskDefinition.addContainer('container', {
32+
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
33+
portMappings: [
34+
{
35+
name: 'api',
36+
containerPort: 80,
37+
},
38+
],
39+
});
40+
41+
const role = new iam.Role(stack, 'Role', {
42+
assumedBy: new iam.ServicePrincipal('ecs.amazonaws.com'),
43+
managedPolicies: [
44+
iam.ManagedPolicy.fromAwsManagedPolicyName('AWSPrivateCAFullAccess'),
45+
],
46+
});
47+
role.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY);
48+
49+
kmsKey.grant(role, 'kms:GenerateDataKeyPair');
50+
51+
new ecs.FargateService(stack, 'FargateService', {
52+
cluster,
53+
taskDefinition,
54+
serviceConnectConfiguration: {
55+
services: [
56+
{
57+
portMappingName: 'api',
58+
dnsName: 'api',
59+
port: 80,
60+
tls: {
61+
awsPcaAuthorityArn: ca.certificateAuthorityArn,
62+
role,
63+
kmsKey,
64+
},
65+
},
66+
],
67+
},
68+
});
69+
70+
new integ.IntegTest(app, 'aws-ecs-service-connect-tls-configuration', {
71+
testCases: [stack],
72+
});
73+
74+
app.synth();

‎packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,10 +952,10 @@ export abstract class BaseService extends Resource
952952

953953
const tls: CfnService.ServiceConnectTlsConfigurationProperty | undefined = svc.tls ? {
954954
issuerCertificateAuthority: {
955-
awsPcaAuthorityArn: svc.tls?.awsPcaAuthorityArn,
955+
awsPcaAuthorityArn: svc.tls.awsPcaAuthorityArn,
956956
},
957-
kmsKey: svc.tls?.kmsKey?.keyArn,
958-
roleArn: svc.tls?.role?.roleArn,
957+
kmsKey: svc.tls.kmsKey?.keyArn,
958+
roleArn: svc.tls.role?.roleArn,
959959
} : undefined;
960960

961961
return {
@@ -1035,6 +1035,7 @@ export abstract class BaseService extends Resource
10351035
!this.isValidPort(serviceConnectService.port)) {
10361036
throw new Error(`Client Alias port ${serviceConnectService.port} is not valid.`);
10371037
}
1038+
10381039
// tls.awsPcaAuthorityArn should be an ARN
10391040
const awsPcaAuthorityArn = serviceConnectService.tls?.awsPcaAuthorityArn;
10401041
if (awsPcaAuthorityArn && !Token.isUnresolved(awsPcaAuthorityArn) && !awsPcaAuthorityArn.startsWith('arn:')) {

0 commit comments

Comments
 (0)