I’m trying to use CDKTF with Typescript to provision EKS clusters in dedicated VPCs, mostly following along with the example GitHub - hashicorp/learn-terraform-provision-eks-cluster.
Is it possible to create the VPC and the EKS cluster? I can’t seem to get the subnet id to resolve correctly. When I try to use DataAwsSubnets with a filter, it can only discover subnets that already exist, and not the ones that are going to be created. Using vpc.privateSubnets to get the list of subnets (like it’s implied in the learning example should work) doesn’t work, it only returns the CIDR range for the subnet and not the subnet ID.
How do you get the IDs for the to-be-created vpc private subnets?
Attempt 1:
let vpc = new Vpc(this, `${details.name}-vpc`, {
...
});
new Eks(this, `${details.name}-eks`, {
clusterName: `${details.name}`,
clusterVersion: "1.25",
vpcId: vpc.vpcIdOutput,
subnetIds: vpc.privateSubnets,
Result 1, during tf apply:
│ Error: creating EKS Cluster (dev): InvalidParameterException:
The subnet ID '10.5.224.0/19' does not exist
(Service: AmazonEC2; Status Code: 400; Error Code:
InvalidSubnetID.NotFound;
Attempt 2:
let subnetData = new DataAwsSubnets(this, `ekssubnets`, {
filter: [{
name: "vpc-id",
values: [vpc.vpcIdOutput]
}],
tags: {
Tier: "private"
}
})
new Eks(this, `${details.name}-eks`, {
clusterName: `${details.name}`,
clusterVersion: "1.25",
vpcId: vpc.vpcIdOutput,
subnetIds: subnetData.ids,
Result 2, during plan:
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: Error in function call
│
│ on .terraform/modules/dev-eks/main.tf line 35, in resource "aws_eks_cluster" "this":
│ 35: subnet_ids = coalescelist(var.control_plane_subnet_ids, var.subnet_ids)
│ ├────────────────
│ │ while calling coalescelist(vals...)
│ │ var.control_plane_subnet_ids is empty list of string
│ │ var.subnet_ids is empty list of string
│
│ Call to function "coalescelist" failed: no non-null arguments.