|
105 | 105 | label="Cluster name", |
106 | 106 | )) |
107 | 107 |
|
| 108 | +custom_eks_ami = Ref(template.add_parameter( |
| 109 | + Parameter( |
| 110 | + "CustomEKSAMI", |
| 111 | + Description="Custom AMI ID for the EKS node group. It is recommended not to set this value, as AWS will automatically select the most optimized image when CustomAMIImageType is specified.", # noqa |
| 112 | + Type="String", |
| 113 | + Default="", |
| 114 | + ), |
| 115 | + group="Elastic Kubernetes Service (EKS)", |
| 116 | + label="Custom EKS AMI", |
| 117 | +)) |
| 118 | + |
| 119 | +use_custom_ami = "UseCustomAMI" |
| 120 | +template.add_condition( |
| 121 | + use_custom_ami, |
| 122 | + Not(Equals(custom_eks_ami, "")) |
| 123 | +) |
| 124 | + |
| 125 | +custom_ami_image_type = Ref(template.add_parameter( |
| 126 | + Parameter( |
| 127 | + "CustomAMIImageType", |
| 128 | + Description="The image type to match the custom AMI. E.g., AL2023_x86_64_STANDARD, AL2_x86_64", |
| 129 | + Type="String", |
| 130 | + Default="", |
| 131 | + ), |
| 132 | + group="Elastic Kubernetes Service (EKS)", |
| 133 | + label="Custom AMI Image Type", |
| 134 | +)) |
| 135 | + |
| 136 | +use_custom_ami_type = "UseCustomAMIType" |
| 137 | +template.add_condition( |
| 138 | + use_custom_ami_type, |
| 139 | + Not(Equals(custom_ami_image_type, "")) |
| 140 | +) |
| 141 | + |
| 142 | +cluster_version = Ref(template.add_parameter( |
| 143 | + Parameter( |
| 144 | + "EksClusterVersion", |
| 145 | + Description="The version of Kubernetes to use for the EKS cluster", |
| 146 | + Type="String", |
| 147 | + Default="", |
| 148 | + ), |
| 149 | + group="Elastic Kubernetes Service (EKS)", |
| 150 | + label="Kubernetes Cluster Version", |
| 151 | +)) |
| 152 | + |
| 153 | +use_cluster_version = "UseEksClusterVersion" |
| 154 | +template.add_condition( |
| 155 | + use_cluster_version, |
| 156 | + Not(Equals(cluster_version, "")) |
| 157 | +) |
| 158 | + |
108 | 159 | cluster = eks.Cluster( |
109 | 160 | "EksCluster", |
110 | 161 | template=template, |
111 | 162 | Name=cluster_name, |
| 163 | + Version=If(use_cluster_version, cluster_version, Ref("AWS::NoValue")), |
112 | 164 | Logging=eks.Logging( |
113 | 165 | ClusterLogging=eks.ClusterLogging( |
114 | 166 | EnabledTypes=[ |
|
145 | 197 | "NodegroupLaunchTemplate", |
146 | 198 | template=template, |
147 | 199 | LaunchTemplateData=ec2.LaunchTemplateData( |
| 200 | + ImageId=If(use_custom_ami, custom_eks_ami, Ref("AWS::NoValue")), |
148 | 201 | BlockDeviceMappings=[ |
149 | 202 | ec2.LaunchTemplateBlockDeviceMapping( |
150 | 203 | DeviceName="/dev/xvda", |
151 | 204 | Ebs=ec2.EBSBlockDevice( |
152 | 205 | DeleteOnTermination=True, |
153 | 206 | Encrypted=use_aes256_encryption, |
154 | 207 | KmsKeyId=If(use_cmk_arn, Ref(cmk_arn), Ref("AWS::NoValue")), |
155 | | - VolumeType="gp2", |
| 208 | + VolumeType="gp3", |
156 | 209 | VolumeSize=container_volume_size, |
157 | 210 | ), |
158 | 211 | ), |
|
179 | 232 | NodeRole=GetAtt(container_instance_role, "Arn"), |
180 | 233 | LaunchTemplate=eks.LaunchTemplateSpecification( |
181 | 234 | Id=Ref(nodegroup_launch_template), |
| 235 | + Version=GetAtt(nodegroup_launch_template, "LatestVersionNumber"), |
182 | 236 | ), |
183 | 237 | # The rest are optional. |
184 | 238 | ScalingConfig=eks.ScalingConfig( |
|
187 | 241 | MinSize=2, |
188 | 242 | ), |
189 | 243 | Subnets=[Ref(private_subnet_a), Ref(private_subnet_b)], |
| 244 | + AmiType=If(use_custom_ami_type, custom_ami_image_type, Ref("AWS::NoValue")) |
190 | 245 | ) |
191 | 246 |
|
192 | 247 | # OUTPUTS |
|
0 commit comments