-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converting dynamic block with local array causes problems #2637
Comments
UpdateSince this issue was posted, we added support for iterators to import constructs as constructs
import cdktf as cdktf
# Provider bindings are generated by running cdktf get.
# See https://cdk.tf/provider-generation for more details.
import ...gen.providers.aws as aws
class MyConvertedCode(constructs.Construct):
def __init__(self, scope, name):
super().__init__(scope, name)
aws.provider.AwsProvider(self, "aws",
default_tags=[AwsProviderDefaultTags(
tags={
"cs_terraform_examples": "aws_security_group/dynamic"
}
)
],
region="us-east-1"
)
ports = [80, 443, 8080]
# In most cases loops should be handled in the programming language context and
# not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
# you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
# you need to keep this like it is.
aws_security_group_changeme_aws_security_group_dynamic_dynamic_iterator0 =
cdktf.TerraformIterator.from_list(cdktf.Token.as_any(ports))
aws.security_group.SecurityGroup(self, "changeme_aws_security_group_dynamic",
name="changeme-aws-security-group-dynamic",
ingress=
aws_security_group_changeme_aws_security_group_dynamic_dynamic_iterator0.dynamic({
"cidr_blocks": ["0.0.0.0/0"],
"description": "changeme-aws-security-group-dynamic-ingress-${" + aws_security_group_changeme_aws_security_group_dynamic_dynamic_iterator0.key + "}",
"from_port": aws_security_group_changeme_aws_security_group_dynamic_dynamic_iterator0.value,
"protocol": "tcp",
"to_port": aws_security_group_changeme_aws_security_group_dynamic_dynamic_iterator0.value
})
) which seems to be better, but returns a different error:
And after fixing that one (by removing the line break) and changing
which might be an error we already track – will check. |
So out of those three (new) problems mentioned, some are already covered by other issues as follows:
|
Update: I created an upstream "issue-PR" for # 2: aws/jsii#4056 |
I'd say we can close this issue now as we do have those three other issues tracking the other problems that now happen when converting the snippet which this issue is based on. What do you think, @mutahhir? |
Created #2800 to track the upstream JSII issue – closing this (as discussed offline with Mutahhir) |
I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Source
Converted
The errors are included in the output, so I'm pasting them here too.
Another example in Python:
The same example seems to work for Typescript, but does not for Python (and possibly other languages)
Solution
Converting the override to a map works well
The text was updated successfully, but these errors were encountered: