2

Problem

I am trying to retrieve the subnet cidr block range using CDKTF data_aws_subnet, but doing so gives me an output as $TfTokenTOKEN instead of an actual cidr range (example 10.42.0.0/24)

Code

import cdktf_cdktf_provider_aws.data_aws_subnet as DataAwssubnet_

self.data_subnet = DataAwssubnet_.DataAwsSubnet(
            self.scope_obj,self.id_, availability_zone = '$$-south-1a', vpc_id='vpc-0d$$$e$$$$2$$$$3')

print(self.data_subnet.cidr_block)

above code outputs some weird encrypted value instead of a string

How can I print this value using data_aws_subnet module of CDKTF?

john mich
  • 2,477
  • 3
  • 17
  • 32

1 Answers1

2

You are looking at a Token there, to print the cidr_block you need to use a TerraformOutput.

import cdktf_cdktf_provider_aws.data_aws_subnet as DataAwssubnet_
from cdktf import TerraformOutput

self.data_subnet = DataAwssubnet_.DataAwsSubnet(
        self.scope_obj,self.id_, availability_zone = '$$-south-1a', vpc_id='vpc-0d$$$e$$$$2$$$$3')

TerraformOutput(self, "subnet_cidr_block", value=self.data_subnet.cidr_block)
Daniel Schmidt
  • 11,605
  • 5
  • 38
  • 70
  • How can I store this in a python variable? – john mich Nov 16 '22 at 12:16
  • 2
    You can only store the token inside of a variable, the real value is not introspectable since the Terraform code is first synthesized by executing your program and then at a second step executed – Daniel Schmidt Nov 17 '22 at 12:00