# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 EnableDnsHostnames: true EnableDnsSupport: true InstanceTenancy: default # Security Group to allow use of VPC Endpoints. VPCEndpointSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: VpcId: !Ref VPC GroupDescription: "Security group to allow use of VPC Endpoints." SecurityGroupIngress: - IpProtocol: tcp Description: HTTPS FromPort: 443 ToPort: 443 CidrIp: 10.0.0.0/0 PrivateSubnetOne: Type: AWS::EC2::Subnet Properties: CidrBlock: 10.0.2.0/24 VpcId: !Ref VPC AvailabilityZone: !Select [ 0, !GetAZs '' ] MapPublicIpOnLaunch: false PrivateSubnetTwo: Type: AWS::EC2::Subnet Properties: CidrBlock: 10.0.3.0/24 VpcId: !Ref VPC AvailabilityZone: !Select [ 1, !GetAZs '' ] MapPublicIpOnLaunch: false PrivateRouteTableOne: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref 'VPC' PrivateRouteTableOneAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref PrivateRouteTableOne SubnetId: !Ref PrivateSubnetOne PrivateRouteTableTwo: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref 'VPC' PrivateRouteTableTwoAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: RouteTableId: !Ref PrivateRouteTableTwo SubnetId: !Ref PrivateSubnetTwo # Interface endpoints. # Enables pulling images from ECR. EcrApiVPCEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnetOne - !Ref PrivateSubnetTwo ServiceName: !Sub com.amazonaws.${AWS::Region}.ecr.api VpcId: !Ref VPC SecurityGroupIds: - !Ref VPCEndpointSecurityGroup EcrDkrVPCEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnetOne - !Ref PrivateSubnetTwo ServiceName: !Sub com.amazonaws.${AWS::Region}.ecr.dkr VpcId: !Ref VPC SecurityGroupIds: - !Ref VPCEndpointSecurityGroup # Gateway endpoint for S3. S3GatewayVPCEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Gateway RouteTableIds: - !Ref PrivateRouteTableOne - !Ref PrivateRouteTableTwo ServiceName: !Sub com.amazonaws.${AWS::Region}.s3 VpcId: !Ref VPC # Enables CloudWatch logging. LogsVPCEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnetOne - !Ref PrivateSubnetTwo ServiceName: !Sub com.amazonaws.${AWS::Region}.logs VpcId: !Ref VPC SecurityGroupIds: - !Ref VPCEndpointSecurityGroup # To enable exec. SSMVPCEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnetOne - !Ref PrivateSubnetTwo ServiceName: !Sub com.amazonaws.${AWS::Region}.ssm VpcId: !Ref VPC SecurityGroupIds: - !Ref VPCEndpointSecurityGroup SSMMessagesVPCEndpoint: Type: AWS::EC2::VPCEndpoint Properties: VpcEndpointType: Interface PrivateDnsEnabled: true SubnetIds: - !Ref PrivateSubnetOne - !Ref PrivateSubnetTwo ServiceName: !Sub com.amazonaws.${AWS::Region}.ssmmessages VpcId: !Ref VPC SecurityGroupIds: - !Ref VPCEndpointSecurityGroup Outputs: VpcId: Value: !Ref VPC PrivateSubnets: Value: !Join [ ',', [ !Ref PrivateSubnetOne, !Ref PrivateSubnetTwo ] ]