How to assign Data Source: aws_availability_zones in CDKTF?

how can I assign the value of the Data Source: aws_availability_zones in CDKTF like this example?

This is my TS code:

this.availabilityZones = new DataAwsAvailabilityZones(
        this,
        `availabilityZones${subnetIndex}`,
        { state: 'available' }
      );

     
      this.subnet = new Subnet(this, `subnet${subnetIndex}`, {
        cidrBlock: config.cidrBlock,
        vpcId: vpcId,
        mapPublicIpOnLaunch: config.mapPublicIpOnLaunch,
        availabilityZone: this.availabilityZones.names[0],
        tags: {
          Name: `vpc_${config.name}`,
          Owner: region.user_id,
        },
      });

This does not work because I get this error:

Error: Found an encoded list token string in a scalar string context. Use 'Fn.element(list, 0)' (not 'list[0]') to extract elements from token lists

Can somebody please help?

this.availabilityZones.names[0]

should be Fn.element(this.availabilityZones.names, 0)

1 Like

thanks @DanielMSchmidt now it works