diff --git a/packages/@aws-cdk/aws-eks/README.md b/packages/@aws-cdk/aws-eks/README.md index 48f157e906c43..c73fd1bd955cc 100644 --- a/packages/@aws-cdk/aws-eks/README.md +++ b/packages/@aws-cdk/aws-eks/README.md @@ -24,7 +24,7 @@ manifests within EKS clusters. This example defines an Amazon EKS cluster with a single pod: ```ts -const cluster = new eks.Cluster(this, 'hello-eks', { vpc }); +const cluster = new eks.Cluster(this, 'hello-eks'); cluster.addCapacity('default', { instanceType: new ec2.InstanceType('t2.medium'), @@ -74,7 +74,6 @@ const clusterAdmin = new iam.Role(this, 'AdminRole', { // now define the cluster and map role to "masters" RBAC group new eks.Cluster(this, 'Cluster', { - vpc: vpc, mastersRole: clusterAdmin }); ``` @@ -242,7 +241,6 @@ the cluster: ```ts new eks.Cluster(this, 'cluster', { - vpc: vpc, kubectlEnabled: false }); ``` diff --git a/packages/@aws-cdk/aws-eks/lib/cluster.ts b/packages/@aws-cdk/aws-eks/lib/cluster.ts index 0c4e4b89dd37c..abbfec968ebb2 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster.ts @@ -87,8 +87,10 @@ export interface ClusterAttributes { export interface ClusterProps { /** * The VPC in which to create the Cluster + * + * @default - a VPC with default configuration will be created and can be accessed through `cluster.vpc`. */ - readonly vpc: ec2.IVpc; + readonly vpc?: ec2.IVpc; /** * Where to place EKS Control Plane ENIs @@ -269,12 +271,12 @@ export class Cluster extends Resource implements ICluster { * @param name the name of the Construct to create * @param props properties in the IClusterProps interface */ - constructor(scope: Construct, id: string, props: ClusterProps) { + constructor(scope: Construct, id: string, props: ClusterProps = { }) { super(scope, id, { physicalName: props.clusterName, }); - this.vpc = props.vpc; + this.vpc = props.vpc || new ec2.Vpc(this, 'DefaultVpc'); this.version = props.version; this.tagSubnets(); @@ -288,7 +290,7 @@ export class Cluster extends Resource implements ICluster { }); const securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'ControlPlaneSecurityGroup', { - vpc: props.vpc, + vpc: this.vpc, description: 'EKS Control Plane Security Group', }); @@ -299,7 +301,7 @@ export class Cluster extends Resource implements ICluster { // Get subnetIds for all selected subnets const placements = props.vpcSubnets || [{ subnetType: ec2.SubnetType.PUBLIC }, { subnetType: ec2.SubnetType.PRIVATE }]; - const subnetIds = [...new Set(Array().concat(...placements.map(s => props.vpc.selectSubnets(s).subnetIds)))]; + const subnetIds = [...new Set(Array().concat(...placements.map(s => this.vpc.selectSubnets(s).subnetIds)))]; const clusterProps: CfnClusterProps = { name: this.physicalName, diff --git a/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.defaults.expected.json b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.defaults.expected.json new file mode 100644 index 0000000000000..2b22287b78df5 --- /dev/null +++ b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.defaults.expected.json @@ -0,0 +1,904 @@ +{ + "Transform": "AWS::Serverless-2016-10-31", + "Resources": { + "ClusterDefaultVpcFA9F2722": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet1Subnet3BFE1BDA": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.0.0/19", + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "AvailabilityZone": "test-region-1a", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet1" + }, + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet1RouteTable1DCCDD98": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet1" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet1RouteTableAssociationAFBE6789": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPublicSubnet1RouteTable1DCCDD98" + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPublicSubnet1Subnet3BFE1BDA" + } + } + }, + "ClusterDefaultVpcPublicSubnet1DefaultRouteCF22EF6E": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPublicSubnet1RouteTable1DCCDD98" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "ClusterDefaultVpcIGW756BE43E" + } + }, + "DependsOn": [ + "ClusterDefaultVpcVPCGWC1D00388" + ] + }, + "ClusterDefaultVpcPublicSubnet1EIP498E2BD2": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc" + } + }, + "ClusterDefaultVpcPublicSubnet1NATGateway6E21013E": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "ClusterDefaultVpcPublicSubnet1EIP498E2BD2", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPublicSubnet1Subnet3BFE1BDA" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet1" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet2SubnetC4E9A966": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.32.0/19", + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "AvailabilityZone": "test-region-1b", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet2" + }, + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet2RouteTable6F1F5F47": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet2" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet2RouteTableAssociationA8539C50": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPublicSubnet2RouteTable6F1F5F47" + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPublicSubnet2SubnetC4E9A966" + } + } + }, + "ClusterDefaultVpcPublicSubnet2DefaultRoute1FA8621E": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPublicSubnet2RouteTable6F1F5F47" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "ClusterDefaultVpcIGW756BE43E" + } + }, + "DependsOn": [ + "ClusterDefaultVpcVPCGWC1D00388" + ] + }, + "ClusterDefaultVpcPublicSubnet2EIP265F4810": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc" + } + }, + "ClusterDefaultVpcPublicSubnet2NATGateway4AF4B728": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "ClusterDefaultVpcPublicSubnet2EIP265F4810", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPublicSubnet2SubnetC4E9A966" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet2" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet3Subnet1A46184A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.64.0/19", + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "AvailabilityZone": "test-region-1c", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet3" + }, + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet3RouteTableC81F99EF": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet3" + } + ] + } + }, + "ClusterDefaultVpcPublicSubnet3RouteTableAssociation7C5D21CC": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPublicSubnet3RouteTableC81F99EF" + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPublicSubnet3Subnet1A46184A" + } + } + }, + "ClusterDefaultVpcPublicSubnet3DefaultRouteB6080504": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPublicSubnet3RouteTableC81F99EF" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "ClusterDefaultVpcIGW756BE43E" + } + }, + "DependsOn": [ + "ClusterDefaultVpcVPCGWC1D00388" + ] + }, + "ClusterDefaultVpcPublicSubnet3EIP0CBF6D05": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc" + } + }, + "ClusterDefaultVpcPublicSubnet3NATGatewayEF4BA49A": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "ClusterDefaultVpcPublicSubnet3EIP0CBF6D05", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPublicSubnet3Subnet1A46184A" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PublicSubnet3" + } + ] + } + }, + "ClusterDefaultVpcPrivateSubnet1Subnet03F39409": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.96.0/19", + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "AvailabilityZone": "test-region-1a", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PrivateSubnet1" + }, + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "kubernetes.io/role/internal-elb", + "Value": "1" + } + ] + } + }, + "ClusterDefaultVpcPrivateSubnet1RouteTable7844020C": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PrivateSubnet1" + }, + { + "Key": "kubernetes.io/role/internal-elb", + "Value": "1" + } + ] + } + }, + "ClusterDefaultVpcPrivateSubnet1RouteTableAssociationF8A67D95": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPrivateSubnet1RouteTable7844020C" + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPrivateSubnet1Subnet03F39409" + } + } + }, + "ClusterDefaultVpcPrivateSubnet1DefaultRouteD624C8BD": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPrivateSubnet1RouteTable7844020C" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "ClusterDefaultVpcPublicSubnet1NATGateway6E21013E" + } + } + }, + "ClusterDefaultVpcPrivateSubnet2SubnetA526AEA7": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.128.0/19", + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "AvailabilityZone": "test-region-1b", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PrivateSubnet2" + }, + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "kubernetes.io/role/internal-elb", + "Value": "1" + } + ] + } + }, + "ClusterDefaultVpcPrivateSubnet2RouteTable1F9A5298": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PrivateSubnet2" + }, + { + "Key": "kubernetes.io/role/internal-elb", + "Value": "1" + } + ] + } + }, + "ClusterDefaultVpcPrivateSubnet2RouteTableAssociationE1240DF2": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPrivateSubnet2RouteTable1F9A5298" + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPrivateSubnet2SubnetA526AEA7" + } + } + }, + "ClusterDefaultVpcPrivateSubnet2DefaultRouteAB55737C": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPrivateSubnet2RouteTable1F9A5298" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "ClusterDefaultVpcPublicSubnet2NATGateway4AF4B728" + } + } + }, + "ClusterDefaultVpcPrivateSubnet3SubnetB64BC839": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "CidrBlock": "10.0.160.0/19", + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "AvailabilityZone": "test-region-1c", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PrivateSubnet3" + }, + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "kubernetes.io/role/internal-elb", + "Value": "1" + } + ] + } + }, + "ClusterDefaultVpcPrivateSubnet3RouteTableF71314D0": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc/PrivateSubnet3" + }, + { + "Key": "kubernetes.io/role/internal-elb", + "Value": "1" + } + ] + } + }, + "ClusterDefaultVpcPrivateSubnet3RouteTableAssociation3007DC36": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPrivateSubnet3RouteTableF71314D0" + }, + "SubnetId": { + "Ref": "ClusterDefaultVpcPrivateSubnet3SubnetB64BC839" + } + } + }, + "ClusterDefaultVpcPrivateSubnet3DefaultRoute932EDFF0": { + "Type": "AWS::EC2::Route", + "Properties": { + "RouteTableId": { + "Ref": "ClusterDefaultVpcPrivateSubnet3RouteTableF71314D0" + }, + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "ClusterDefaultVpcPublicSubnet3NATGatewayEF4BA49A" + } + } + }, + "ClusterDefaultVpcIGW756BE43E": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "eks-integ-defaults/Cluster/DefaultVpc" + } + ] + } + }, + "ClusterDefaultVpcVPCGWC1D00388": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + }, + "InternetGatewayId": { + "Ref": "ClusterDefaultVpcIGW756BE43E" + } + } + }, + "ClusterClusterRoleCE5C05DD": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "eks.", + { + "Ref": "AWS::URLSuffix" + } + ] + ] + } + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/AmazonEKSClusterPolicy" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/AmazonEKSServicePolicy" + ] + ] + } + ] + } + }, + "ClusterControlPlaneSecurityGroupD274242C": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "EKS Control Plane Security Group", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "SecurityGroupIngress": [], + "VpcId": { + "Ref": "ClusterDefaultVpcFA9F2722" + } + } + }, + "ClusterResourceHandlerServiceRole7FB16465": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "lambda.", + { + "Ref": "AWS::URLSuffix" + } + ] + ] + } + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "ClusterResourceHandlerServiceRoleDefaultPolicy333D0E3A": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "eks:CreateCluster", + "eks:DescribeCluster", + "eks:DeleteCluster" + ], + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": "iam:PassRole", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "ClusterClusterRoleCE5C05DD", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "ClusterResourceHandlerServiceRoleDefaultPolicy333D0E3A", + "Roles": [ + { + "Ref": "ClusterResourceHandlerServiceRole7FB16465" + } + ] + } + }, + "ClusterResourceHandler28BF924D": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "ClusterResourceHandlerCodeS3Bucket1A051297" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "ClusterResourceHandlerCodeS3VersionKeyD4764A45" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "ClusterResourceHandlerCodeS3VersionKeyD4764A45" + } + ] + } + ] + } + ] + ] + } + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ClusterResourceHandlerServiceRole7FB16465", + "Arn" + ] + }, + "Runtime": "python3.7", + "Layers": [ + { + "Fn::GetAtt": [ + "kubectllayer8C2542BCBF2B4DFEB765E181FD30A9A0617C4ADA", + "Outputs.LayerVersionArn" + ] + } + ], + "MemorySize": 512, + "Timeout": 900 + }, + "DependsOn": [ + "ClusterResourceHandlerServiceRoleDefaultPolicy333D0E3A", + "ClusterResourceHandlerServiceRole7FB16465" + ] + }, + "Cluster9EE0221C": { + "Type": "Custom::AWSCDK-EKS-Cluster", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "ClusterResourceHandler28BF924D", + "Arn" + ] + }, + "Config": { + "roleArn": { + "Fn::GetAtt": [ + "ClusterClusterRoleCE5C05DD", + "Arn" + ] + }, + "resourcesVpcConfig": { + "securityGroupIds": [ + { + "Fn::GetAtt": [ + "ClusterControlPlaneSecurityGroupD274242C", + "GroupId" + ] + } + ], + "subnetIds": [ + { + "Ref": "ClusterDefaultVpcPublicSubnet1Subnet3BFE1BDA" + }, + { + "Ref": "ClusterDefaultVpcPublicSubnet2SubnetC4E9A966" + }, + { + "Ref": "ClusterDefaultVpcPublicSubnet3Subnet1A46184A" + }, + { + "Ref": "ClusterDefaultVpcPrivateSubnet1Subnet03F39409" + }, + { + "Ref": "ClusterDefaultVpcPrivateSubnet2SubnetA526AEA7" + }, + { + "Ref": "ClusterDefaultVpcPrivateSubnet3SubnetB64BC839" + } + ] + } + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "ClusterKubernetesResourceHandler81C19BC8": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "ClusterKubernetesResourceHandlerCodeS3Bucket8DF6F33F" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "ClusterKubernetesResourceHandlerCodeS3VersionKeyE1F5124A" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "ClusterKubernetesResourceHandlerCodeS3VersionKeyE1F5124A" + } + ] + } + ] + } + ] + ] + } + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ClusterResourceHandlerServiceRole7FB16465", + "Arn" + ] + }, + "Runtime": "python3.7", + "Environment": { + "Variables": { + "CLUSTER_NAME": { + "Ref": "Cluster9EE0221C" + } + } + }, + "Layers": [ + { + "Fn::GetAtt": [ + "kubectllayer8C2542BCBF2B4DFEB765E181FD30A9A0617C4ADA", + "Outputs.LayerVersionArn" + ] + } + ], + "MemorySize": 256, + "Timeout": 900 + }, + "DependsOn": [ + "ClusterResourceHandlerServiceRoleDefaultPolicy333D0E3A", + "ClusterResourceHandlerServiceRole7FB16465" + ] + }, + "kubectllayer8C2542BCBF2B4DFEB765E181FD30A9A0617C4ADA": { + "Type": "AWS::Serverless::Application", + "Properties": { + "Location": { + "ApplicationId": "arn:aws:serverlessrepo:us-east-1:903779448426:applications/lambda-layer-kubectl", + "SemanticVersion": "1.13.7" + }, + "Parameters": { + "LayerName": "kubectl-459230f5f24751b9afdd68c6a69be4c7" + } + } + } + }, + "Parameters": { + "ClusterResourceHandlerCodeS3Bucket1A051297": { + "Type": "String", + "Description": "S3 bucket for asset \"eks-integ-defaults/Cluster/Resource/ResourceHandler/Code\"" + }, + "ClusterResourceHandlerCodeS3VersionKeyD4764A45": { + "Type": "String", + "Description": "S3 key for asset version \"eks-integ-defaults/Cluster/Resource/ResourceHandler/Code\"" + }, + "ClusterResourceHandlerCodeArtifactHashA32F2E77": { + "Type": "String", + "Description": "Artifact hash for asset \"eks-integ-defaults/Cluster/Resource/ResourceHandler/Code\"" + }, + "ClusterKubernetesResourceHandlerCodeS3Bucket8DF6F33F": { + "Type": "String", + "Description": "S3 bucket for asset \"eks-integ-defaults/Cluster/KubernetesResourceHandler/Code\"" + }, + "ClusterKubernetesResourceHandlerCodeS3VersionKeyE1F5124A": { + "Type": "String", + "Description": "S3 key for asset version \"eks-integ-defaults/Cluster/KubernetesResourceHandler/Code\"" + }, + "ClusterKubernetesResourceHandlerCodeArtifactHash27D4393F": { + "Type": "String", + "Description": "Artifact hash for asset \"eks-integ-defaults/Cluster/KubernetesResourceHandler/Code\"" + } + }, + "Outputs": { + "ClusterClusterNameEB26049E": { + "Value": { + "Ref": "Cluster9EE0221C" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.defaults.ts b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.defaults.ts new file mode 100644 index 0000000000000..cf16cd45255ad --- /dev/null +++ b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.defaults.ts @@ -0,0 +1,23 @@ +import cdk = require('@aws-cdk/core'); +import eks = require('../lib'); + +class EksClusterStack extends cdk.Stack { + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); + + new eks.Cluster(this, 'Cluster'); + } +} + +const app = new cdk.App(); + +// since the EKS optimized AMI is hard-coded here based on the region, +// we need to actually pass in a specific region. +new EksClusterStack(app, 'eks-integ-defaults', { + env: { + region: process.env.CDK_INTEG_REGION || process.env.CDK_DEFAULT_REGION, + account: process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT, + } +}); + +app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-eks/test/test.cluster.ts b/packages/@aws-cdk/aws-eks/test/test.cluster.ts index 61fbe0068843c..e11b73f2b059a 100644 --- a/packages/@aws-cdk/aws-eks/test/test.cluster.ts +++ b/packages/@aws-cdk/aws-eks/test/test.cluster.ts @@ -2,7 +2,7 @@ import { expect, haveResource, haveResourceLike, not } from '@aws-cdk/assert'; import ec2 = require('@aws-cdk/aws-ec2'); import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/core'); -import { CfnOutput } from '@aws-cdk/core'; +import { CfnOutput, Stack } from '@aws-cdk/core'; import { Test } from 'nodeunit'; import eks = require('../lib'); import { KubernetesResource } from '../lib'; @@ -33,6 +33,18 @@ export = { test.done(); }, + 'if "vpc" is not specified, vpc with default configuration will be created'(test: Test) { + // GIVEN + const stack = new Stack(); + + // WHEN + new eks.Cluster(stack, 'cluster'); + + // THEN + expect(stack).to(haveResource('AWS::EC2::VPC')); + test.done(); + }, + 'creating a cluster tags the private VPC subnets'(test: Test) { // GIVEN const { stack, vpc } = testFixture();