Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: version updates, including breaking changes in jsii (backport #22382) #22464

Merged
merged 7 commits into from
Oct 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
revert custom resource test changes
comcalvi committed Oct 12, 2022

Verified

This commit was signed with the committer’s verified signature.
pradyunsg Pradyun Gedam
commit fe7bdd254bc90078be1f61fa6e67457267f070b3
Original file line number Diff line number Diff line change
@@ -743,170 +743,3 @@ test('assumedRoleArn adds statement for sts:assumeRole', () => {
},
});
});

test('fails when at least one of policy or role is not specified', () => {
const stack = new cdk.Stack();
expect(() => new AwsCustomResource(stack, 'AwsSdk', {
onUpdate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
parameters: {
param: 'param',
},
},
})).toThrow(/`policy`.+`role`/);
});

test('can provide no policy if using existing role', () => {
// GIVEN
const stack = new cdk.Stack();
const role = iam.Role.fromRoleArn(stack, 'Role', 'arn:aws:iam::123456789012:role/CoolRole');
// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
},
role,
});
// THEN
Template.fromStack(stack).resourceCountIs('AWS::IAM::Role', 0);
Template.fromStack(stack).resourceCountIs('AWS::IAM::Policy', 0);
});

test('can specify VPC', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'TestVpc');

// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }),
vpc,
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
VpcConfig: {
SubnetIds: stack.resolve(vpc.privateSubnets.map(subnet => subnet.subnetId)),
},
});
});

test('specifying public subnets results in a synthesis error', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'TestVpc');

// THEN
expect(() => {
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }),
vpc,
vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
});
}).toThrow(/Lambda Functions in a public subnet/);
});

test('not specifying vpcSubnets when only public subnets exist on a VPC results in an error', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'TestPublicOnlyVpc', {
subnetConfiguration: [{ name: 'public', subnetType: ec2.SubnetType.PUBLIC }],
});

// THEN
expect(() => {
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }),
vpc,
});
}).toThrow(/Lambda Functions in a public subnet/);
});

test('vpcSubnets filter is not required when only isolated subnets exist', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'TestPrivateOnlyVpc', {
subnetConfiguration: [
{ name: 'test1private', subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
{ name: 'test2private', subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
],
});

// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }),
vpc,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
VpcConfig: {
SubnetIds: stack.resolve(vpc.isolatedSubnets.map(subnet => subnet.subnetId)),
},
});
});

test('vpcSubnets filter is not required for the default VPC configuration', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'TestVpc');

// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }),
vpc,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
VpcConfig: {
SubnetIds: stack.resolve(vpc.privateSubnets.map(subnet => subnet.subnetId)),
},
});
});

test('vpcSubnets without vpc results in an error', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
expect(() => new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.of('id'),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }),
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
})).toThrow('Cannot configure \'vpcSubnets\' without configuring a VPC');
});

This file was deleted.