|
1 | 1 | import { testDeprecated } from '@aws-cdk/cdk-build-tools';
|
2 | 2 | import { Annotations, Match, Template } from '../../assertions';
|
3 | 3 | import { App, CfnOutput, CfnResource, Fn, Lazy, Stack, Tags } from '../../core';
|
4 |
| -import { EC2_RESTRICT_DEFAULT_SECURITY_GROUP } from '../../cx-api'; |
| 4 | +import { EC2_REQUIRE_PRIVATE_SUBNETS_FOR_EGRESSONLYINTERNETGATEWAY, EC2_RESTRICT_DEFAULT_SECURITY_GROUP } from '../../cx-api'; |
5 | 5 | import {
|
6 | 6 | AclCidr,
|
7 | 7 | AclTraffic,
|
@@ -2747,6 +2747,90 @@ describe('vpc', () => {
|
2747 | 2747 | },
|
2748 | 2748 | });
|
2749 | 2749 | });
|
| 2750 | + test('EgressOnlyIGW is created if no private subnet configured in dual stack and feature flag EC2_REQUIRE_PRIVATE_SUBNETS_FOR_EGRESSONLYINTERNETGATEWAY is not enabled', () => { |
| 2751 | + // GIVEN |
| 2752 | + const app = new App(); |
| 2753 | + const stack = new Stack(app, 'DualStackStack'); |
| 2754 | + |
| 2755 | + // WHEN |
| 2756 | + const vpc = new Vpc(stack, 'Vpc', { |
| 2757 | + ipProtocol: IpProtocol.DUAL_STACK, |
| 2758 | + subnetConfiguration: [ |
| 2759 | + { |
| 2760 | + subnetType: SubnetType.PUBLIC, |
| 2761 | + name: 'public', |
| 2762 | + }, |
| 2763 | + ], |
| 2764 | + }); |
| 2765 | + |
| 2766 | + // THEN |
| 2767 | + Template.fromStack(stack).resourceCountIs('AWS::EC2::EgressOnlyInternetGateway', 1); |
| 2768 | + }); |
| 2769 | + test('EgressOnlyIGW is created if a private subnet is configured in dual stack and feature flag EC2_REQUIRE_PRIVATE_SUBNETS_FOR_EGRESSONLYINTERNETGATEWAY is not enabled', () => { |
| 2770 | + // GIVEN |
| 2771 | + const app = new App(); |
| 2772 | + const stack = new Stack(app, 'DualStackStack'); |
| 2773 | + |
| 2774 | + // WHEN |
| 2775 | + const vpc = new Vpc(stack, 'Vpc', { |
| 2776 | + ipProtocol: IpProtocol.DUAL_STACK, |
| 2777 | + subnetConfiguration: [ |
| 2778 | + { |
| 2779 | + subnetType: SubnetType.PUBLIC, |
| 2780 | + name: 'public', |
| 2781 | + }, |
| 2782 | + { |
| 2783 | + subnetType: SubnetType.PRIVATE_WITH_EGRESS, |
| 2784 | + name: 'private', |
| 2785 | + }, |
| 2786 | + ], |
| 2787 | + }); |
| 2788 | + |
| 2789 | + // THEN |
| 2790 | + Template.fromStack(stack).resourceCountIs('AWS::EC2::EgressOnlyInternetGateway', 1); |
| 2791 | + }); |
| 2792 | + |
| 2793 | + test('EgressOnlyIGW is created if a private subnet is configured in dual stack and feature flag EC2_REQUIRE_PRIVATE_SUBNETS_FOR_EGRESSONLYINTERNETGATEWAY is enabled', () => { |
| 2794 | + // GIVEN |
| 2795 | + const app = new App(); |
| 2796 | + const stack = new Stack(app, 'DualStackStack'); |
| 2797 | + // WHEN |
| 2798 | + stack.node.setContext(EC2_REQUIRE_PRIVATE_SUBNETS_FOR_EGRESSONLYINTERNETGATEWAY, true); |
| 2799 | + const vpc = new Vpc(stack, 'Vpc', { |
| 2800 | + ipProtocol: IpProtocol.DUAL_STACK, |
| 2801 | + subnetConfiguration: [ |
| 2802 | + { |
| 2803 | + subnetType: SubnetType.PUBLIC, |
| 2804 | + name: 'public', |
| 2805 | + }, |
| 2806 | + { |
| 2807 | + subnetType: SubnetType.PRIVATE_WITH_EGRESS, |
| 2808 | + name: 'private', |
| 2809 | + }, |
| 2810 | + ], |
| 2811 | + }); |
| 2812 | + |
| 2813 | + // THEN |
| 2814 | + Template.fromStack(stack).resourceCountIs('AWS::EC2::EgressOnlyInternetGateway', 1); |
| 2815 | + }); |
| 2816 | + test('EgressOnlyIGW is not created if no private subnet is configured in dual stack and feature flag EC2_REQUIRE_PRIVATE_SUBNETS_FOR_EGRESSONLYINTERNETGATEWAY is enabled', () => { |
| 2817 | + // GIVEN |
| 2818 | + const app = new App(); |
| 2819 | + const stack = new Stack(app, 'DualStackStack'); |
| 2820 | + stack.node.setContext(EC2_REQUIRE_PRIVATE_SUBNETS_FOR_EGRESSONLYINTERNETGATEWAY, true); |
| 2821 | + // WHEN |
| 2822 | + const vpc = new Vpc(stack, 'Vpc', { |
| 2823 | + ipProtocol: IpProtocol.DUAL_STACK, |
| 2824 | + subnetConfiguration: [ |
| 2825 | + { |
| 2826 | + subnetType: SubnetType.PUBLIC, |
| 2827 | + name: 'public', |
| 2828 | + }, |
| 2829 | + ], |
| 2830 | + }); |
| 2831 | + // THEN |
| 2832 | + Template.fromStack(stack).resourceCountIs('AWS::EC2::EgressOnlyInternetGateway', 0); |
| 2833 | + }); |
2750 | 2834 |
|
2751 | 2835 | test('error should occur if IPv6 properties are provided for a non-dual-stack VPC', () => {
|
2752 | 2836 | // GIVEN
|
|
0 commit comments