Skip to content
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

aws_acm_certificate.*.domain_validation_options throws Invalid index #424

Closed
Tracked by #525
YouDonggeun opened this issue Nov 9, 2020 · 5 comments
Closed
Tracked by #525
Labels
bug Something isn't working cdktf schema

Comments

@YouDonggeun
Copy link

YouDonggeun commented Nov 9, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

ctktf : 0.0.17-pre.131/typescript
ts: 4.0.5
aws-providers: 3.14.1

Affected Resource(s)

Debug Output

Expected Behavior

Error: Invalid index

  on cdk.tf.json line 7420, in resource.aws_route53_record.cdktf_notificationcertvalidationrecord_16141CAD:
7420:         "name": "${aws_acm_certificate.cdktf_notificationappcertificate_680C64C0.domain_validation_options.0.resource_record_name}",

This value does not have any indices.

Actual Behavior

"${tolist(aws_acm_certificate.cdktf_notificationappcertificate_680C64C0.domain_validation_options).0.resource_record_name}"
        

when added "tolist" into cdk.tf.json it works completed

Steps to Reproduce

Important Factoids

References

ref: hashicorp/terraform#26043

bug fix Implement

ComplexComputedToList

import { ITerraformResource, Token } from "cdktf";

export class ComplexComputedToList {
    terraformResource: ITerraformResource;
    terraformAttribute: string;
    index: string;
    /**
     * @experimental
     */
    constructor(
        terraformResource: ITerraformResource,
        terraformAttribute: string,
        index: string
    ) {
        this.terraformResource = terraformResource;
        this.terraformAttribute = terraformAttribute;
        this.index = index;
    }
    /**
     * @experimental
     */
    getStringAttribute(terraformAttribute: string) {
        return Token.asString(
            this.interpolationForAttribute(terraformAttribute)
        );
    }
    /**
     * @experimental
     */
    getNumberAttribute(terraformAttribute: string) {
        return Token.asNumber(
            this.interpolationForAttribute(terraformAttribute)
        );
    }
    /**
     * @experimental
     */
    getListAttribute(terraformAttribute: string) {
        return Token.asList(this.interpolationForAttribute(terraformAttribute));
    }
    /**
     * @experimental
     */
    getBooleanAttribute(terraformAttribute: string) {
        return Token.asString(
            this.interpolationForAttribute(terraformAttribute)
        );
    }
    /**
     * @experimental
     */
    interpolationForAttribute(property: string) {
        const {
            terraformResourceType,
            friendlyUniqueId,
        } = this.terraformResource;
        return `\${tolist(${terraformResourceType}.${friendlyUniqueId}.${this.terraformAttribute})[${this.index}].${property}}`;
    }
}

someConvertTest.ts

class CustomAcmCertificateDomainValidationOptions extends ComplexComputedToList {
    // domain_name - computed: true, optional: false, required: true
    public get domainName() {
        return this.getStringAttribute("domain_name");
    }

    // resource_record_name - computed: true, optional: false, required: true
    public get resourceRecordName() {
        return this.getStringAttribute("resource_record_name");
    }

    // resource_record_type - computed: true, optional: false, required: true
    public get resourceRecordType() {
        return this.getStringAttribute("resource_record_type");
    }

    // resource_record_value - computed: true, optional: false, required: true
    public get resourceRecordValue() {
        return this.getStringAttribute("resource_record_value");
    }
}
const convertDomainValidationOptions = (cert: AcmCertificate, index: string) =>
    new CustomAcmCertificateDomainValidationOptions(
        cert,
        "domain_validation_options",
        index
    );
@YouDonggeun YouDonggeun added the bug Something isn't working label Nov 9, 2020
@jsteinich
Copy link
Collaborator

This may require a bit of discussion. Currently lists and sets are treated the same in cdktf; however, they aren't the same in Terraform. The workaround proposed here would allow accessing by index; however, I believe converting a set to a list doesn't guarantee ordering which could result in differences between plans. Actually generating a set type is possible, but a lack of generic support would make it a fairly large task.

@skorfmann
Copy link
Contributor

@jsteinich do you have something in mind how to tackle this?

@jsteinich
Copy link
Collaborator

@jsteinich do you have something in mind how to tackle this?

Ideally jsii would support Set<T> just like they support Array<T>. I'd be willing to work on that; however, I think we have bigger issues to figure out with referencing computed collections. aws/jsii#1841 would go a long way, but even that may not be enough. I also came across aws/jsii#1302. I'll try to write up some more thoughts when I have a bit more time.

@DanielMSchmidt
Copy link
Contributor

#992 tracks this issue, Closing this one so we only have one issue that tracks the effort

ansgarm added a commit that referenced this issue Dec 13, 2021
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Dec 16, 2021
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Jan 4, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Jan 14, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Jan 14, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Jan 17, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Jan 18, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Jan 18, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424
ansgarm added a commit that referenced this issue Jan 18, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424

fix(provider-generator): don't supply third arg for String|Number|Boolean Map types. remove return type to let TS narrow it down automatically to give a narrower type
ansgarm added a commit that referenced this issue Jan 18, 2022
for providers sets are exposed as lists (as they previously were) but when setting or retrieving them, the returned token will be wrapped in toset or tolist respectively. As sets are not yet supported by JSII, we will convert them to lists so that accessing individual elements works as inferred from the array type which is currently used to model sets in TypeScript. Addresses for example #424

fix(provider-generator): don't supply third arg for String|Number|Boolean Map types. remove return type to let TS narrow it down automatically to give a narrower type
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working cdktf schema
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants