I am generating list of VPCs ID per region dynamically using boto3(and outside the scope of the terraform stack) and its named as “aws_vpc_list_per_region”.
How can I iterate over this list for creating resources in CDKTF for a given stack?
Below is snippet of the code and how I am trying escape hatch using add_override.
If aws_vpc_list_per_region contains the ids already, you could also use a loop in Python and create multiple instances of AwsTgwVpcAttachment and pass each of them a different id and a different vpc_id.
Hi @ansgarm . thanks for replying. I know I can do that ( ) but there is more to the story.
Story: I am migrating the code from HCL (which is already deployed) to Python.
in HCL, AwsTgwVpcAttachment construct has only one id (eg. aws_tgw_vpc_attachment_abc) (in HCL context, its the name of the resource:aws_tgw_vpc_attachment).
I am going to import the config from different state file(created by HCL) to a state file created by python. this is were things gets clumsy as I have to import each VPC if I take the approach you suggested.
the clean code would be to use add_override and I wonder if there is way to make it work.
Unfortunately, it doesn’t work and throws the error while executing the Terraform stack.
╷
│ Error: Extraneous JSON object property
│
│ on cdk.tf.json line 175:
│ 175: "for_each": "${([vpc-abc])}"
│
│ No argument or block type is named "for_each".
I tried few other things but no luck so far.I’ll let everyone know if I find a solution.
│ Error: github.com/kbst/terraform-provider-kustomize/kustomize.kustomizationResourceCreate: JSON parse error: invalid character 'r' looking for beginning of value