-
Notifications
You must be signed in to change notification settings - Fork 459
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
Maintain dependencies between required construct properties #310
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool - thanks for your initiative 👍 Just looked briefly into this and will test it locally later today.
This ended being a lot more complicated than I expected: partially because providers and resources/data sources shared the same code, but mostly because of the complexities (and inconsistencies) of schema definition.
Yes, there's lots of headroom for improvements and refactoring around the schema generation 👍
I'm pretty sure I fixed a couple bugs, but I'm not confident that I didn't introduce new ones, so I want to do some more testing before switching from draft.
Makes sense, will try it as well
packages/cdktf-cli/test/get/generator/__snapshots__/complex-computed-types.test.ts.snap
Show resolved
Hide resolved
faa5f81
to
ae737ce
Compare
I checked diffs against all of the pre-built provider repos. Changes appear to be what I expected them to be.
|
Do you have an example for this? |
https://www.terraform.io/docs/providers/docker/d/docker_network.html |
Right, and that's now being built correctly? |
Yep. |
c920cae
to
5cb741b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently there's typescript limitation around differently typed getters / setters :
// In DataAwsRoute53Zone
// zone_id - computed: true, optional: true, required: false
private _zoneId?: string;
public get zoneId() {
return this.getStringAttribute('zone_id');
}
public set zoneId(value: string | undefined) {
this._zoneId = value;
}
While the code seems to be correct, the typescript compiler doesn't accept it:
Looks like that both functions have to set and return the same type.
I'm wondering what the best way to handle this would be.
ps: And yes, it's a change compared to what we had before:
I'm not quite sure how we didn't have the same problem before since the getter and setter certainly seem to have different types.
I'm not sure. Given #233, I don't know if we can disallow setting an optional property to null. If we could, that could be a fairly straightforward option. |
Also, I'll make sure to add some test cases to pick this up. |
I'm pretty sure we have similar issues - looks like the setter type wins in this case. It's just the type information getting mixed up.
Yes, I think being able to set the value to null should be possible. |
I want to look into it farther, but my initial digging makes it seem like null has primarily been used in module development and isn't used much otherwise. If that's true, perhaps we could making using a null a bit of a special case...
|
How would you remove an attribute which was set somewhere already? I think that's difficult, if you can't provide null.
This wouldn't feel natural to me. Null seems to be totally valid use case to me. I'll also think a bit about it today, not sure what a good option would be right now. |
There are several different types of attributes:
HCL allows any attribute to be referenced. There are likely some cases where a reference causes an error at plan/apply time, but that seems outside the scope of cdktf Given all the properties of attributes, the following seems ideal:
All of that is possible except for mixed type getter/setter (see microsoft/TypeScript#2521).
In my opinion, number 6 is the best option since it works as expected for everything besides using null, which I expect to be a relatively less common usage. |
@jsteinich thanks for this great summary!
In the specific example I wrote earlier this would like this then? // In DataAwsRoute53Zone
// zone_id - computed: true, optional: true, required: false
private _zoneId?: string;
public get zoneId() {
return this.getStringAttribute('zone_id');
}
public set zoneId(value: string) {
this._zoneId = value;
}
// setting null like this?
public set resetZoneId {
this._zoneId = null;
}
// or
public set zoneIdReset {
this._zoneId = null;
} |
Almost. The null support would be a bit different: // In DataAwsRoute53Zone
// zone_id - computed: true, optional: true, required: false
private _zoneId?: string;
public get zoneId() {
return this.getStringAttribute('zone_id');
}
public set zoneId(value: string) {
this._zoneId = value;
}
public setZoneId(value: string | undefined) {
this._zoeId = value;
} The naming of the extra method might need to be adjusted to account for jsii Java code. public set resetZoneId {
this._zoneId = null;
} is more like option 7. |
public setZoneId(value: string | undefined) {
this._zoeId = value;
} Wouldn't this be invalid in Java or C# ? - I think I saw jsii complain about that naming schema. |
Sorry - didn't read the full comment :D |
Why would you prefer something like public setZoneId(value: string | undefined) {
this._zoeId = value;
} over this public set resetZoneId {
this._zoneId = null;
} when the only use-case seems to be resetting a potentially set value to |
I was thinking there would be another use case for modules that optionally set data, but actually they would probably just do so in the props provided in the constructor. Having the reset would probably work better with jsii naming, so I'm fine going that route. |
👍
Yes, I agree. That's probably the best solution within the given constraints. |
aed2bf5
to
bf4bcfd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it in several local demos of mine, looks pretty good 👍
I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Fixes #188 Also eliminates #214
This ended being a lot more complicated than I expected: partially because providers and resources/data sources shared the same code, but mostly because of the complexities (and inconsistencies) of schema definition.
I'm pretty sure I fixed a couple bugs, but I'm not confident that I didn't introduce new ones, so I want to do some more testing before switching from draft.