hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.84k stars 450 forks source link

All Module Outputs Typed as String #287

Open skorfmann opened 4 years ago

skorfmann commented 4 years ago

Community Note

cdktf & Language Versions

Affected Resource(s)

Debug Output

E.g the AWS VPC Module:

public get publicSubnetsOutput(): string {
    return this.interpolationForOutput('public_subnets')
  }

Expected Behavior

This should be treated as list of strings

Actual Behavior

It's treated as simple string

Steps to Reproduce

Import VPC module and reference the output

orendain commented 2 years ago

In the meantime, are there workarounds that are expected to work?

@jsteinich wrote in #606:

You could try using Token.asList on the module output to workaround.

In my case, I have an output that should be recognized as an object w/ a couple of attributes. I'm struggling to have it recognized as such. Using Token().as_any will still result in AttributeError: '<class 'cdktf._IResolvableProxy'>' object has no attribute 'my_attribute' when synthesizing.

jsteinich commented 2 years ago

In my case, I have an output that should be recognized as an object w/ a couple of attributes. I'm struggling to have it recognized as such. Using Token().as_any will still result in AttributeError: '<class 'cdktf._IResolvableProxy'>' object has no attribute 'my_attribute' when synthesizing.

You could manually construct hcl and use escape hatches, but probably easier to try to use Fn.lookup. Should just be able to pass the output directly, the name of the attribute, and a default value to the function.

c0deaddict commented 1 year ago

I also encounter this bug using Python with the CDKTF and the VPC module. Is there any known workaround for Python? I tried typing.cast(list[str], self.vpc.private_subnet_outputs) but that doesn't change anything.

Update Found it! Token.as_list(self.vpc.private_subnet_outputs) seems to work

josh-thisisbud commented 1 year ago

This sort of thing needs to be documented.

starbuggx commented 2 months ago

Token.as_list is working with a list from _output, but when I tried to get a target group arn from target_groups_output, the original output is string, but after I tried Token.as_list, Token.as_string_map(dict), I still cannot get the arn.