Access to a single element in a set type returned by a datasource in CDKTF

I have the following scenario:

subnets = DataAwsSubnetIds(self, 'subnets',
            vpc_id = "vpc-xxxxxx",
            filter           = [{
               "name"   : "tag:Name",
               "values" : ["private*"]

And after I retreieve the subnets id, I would like to use it on a Instance.

ec2 = Instance(self, instance,
                ami = xxxxxx,
                instance_type = "t3.micro",                
                subnet_id = Token.as_string(subnets.ids),


This will be causing an error as this value is a SET of ids.
How can I get a single subnet_id to pass to my Instance ?


Support for that is a bit rough currently, but I believe something like this will work:
subnet_id = f'${{tolist({subnets.fqn}.ids)[0]}}'

1 Like

Thanks for your answer. I finally get the whole list and added to the ASG. I will try this solution once I had this issue again.