Hi all, Trying to create EKS clusters in an exist...
# general
e
Hi all, Trying to create EKS clusters in an existing VPC and subnets using Pulumi. Currently struggling to retrieve information about the existing VPC and its subnets using just the VPC id. I also need to distinguish between the private and public subnets of that VPC, because I want to create the managed node group in the private subnets. I tried using
Vpc.fromExistingIds
by passing the existing vpc id, but it doesn't seem to populate the
publicSubnetIds
and
publicSubnetIds
fields of the resulting object.
aws.ec2.getVpc
or
aws.ec2.getSubnets
don't distinguish between public and private subnets. Am I missing something obvious? Is there some other way to do it? The existing VPC and subnets should not be managed by the stack that is creating the clusters. Thanks.
b
Hi Alex, Maybe not the only solution, but I can give you the code we used to do that (python code, but you should be able to reproduce in any other language)
Copy code
aws.ec2.get_subnets(
        filters=[
            aws.ec2.GetSubnetsFilterArgs(name="vpc-id", values=[vpc.id]),
            aws.ec2.GetSubnetsFilterArgs(
                name="availability-zone", values=availability_zones
            ),
            aws.ec2.GetSubnetsFilterArgs(name=f"tag:{tag_key}", values=[tag_value]),
        ],
        opts=pulumi.InvokeOptions(provider=provider),
    )
With the get_subnets function, you can retrieve subnets thanks to different filters (such as vpc-id, az, and tags in my case)
e
Hi Joffrey, Thanks for the snippet. I also found out in the meantime, that I can distinguish between public or private subnets by filtering in get_subnets on
map-public-ip-on-launch
so this solves my problem.