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

feat: Model ComplexComputedLists as ComplexLists and ComputedObjects #1499

Merged
merged 12 commits into from
Mar 17, 2022

Conversation

ansgarm
Copy link
Member

@ansgarm ansgarm commented Jan 20, 2022

Closes #993

Open Subtasks

  • Write upgrade guide (ucloud examples might be helpful to link)
  • Add link to upgrade guide to Changelog

@ansgarm ansgarm changed the title refactor: remove isSingleItem property from ComplexObjects feat: Model complex lists as arrays Jan 20, 2022
@ansgarm ansgarm force-pushed the complex-lists-as-arrays branch 4 times, most recently from 6b6456b to 031837b Compare January 25, 2022 11:07
@ansgarm
Copy link
Member Author

ansgarm commented Jan 25, 2022

Quick update on this PR

Today we (@skorfmann, @DanielMSchmidt, @jsteinich and I) had a deeper look into the changes that this PR would introduce.
It models complex computed lists (i.e. "read-only" lists of objects that only have values after a resource has been provisioned) as an array which better reflects the underlying data. But as the length and contents of this array are only known "at runtime", they are modeled as arrays of a single token (similar to how e.g. string arrays are also modeled currently). While this allows accessing the whole list at once (which is currently not possible without self constructed references), it makes accessing a single item for a (at synth time) known index particularly hard. Which is an understatement. It is really bad. See the following two examples for yourselves:

// with ComplexComputedLists (previously)
ImageId: images.Images(jsii.String("0")).Id(),
// with Arrays of ComplexListItems (this PR)
ImageId: cdktf.Token_AsString(cdktf.Fn_Lookup(cdktf.Fn_Element(images.Images, 0), jsii.String("id"), jsii.String("")), &cdktf.EncodingOptions{}),

TypeScript is less bad, but still terrible:

// with ComplexComputedLists (previously)
imageId: images.images("0").id,
// with Arrays of ComplexListItems (now)
imageId: Token.asString(Fn.lookup(Fn.element(images.images, 0), "id", "")),

As this does not makes things simpler (besides allowing to access a whole list directly via e.g. images.Images), we decided to revisit the implementation and make some adjustments to it.

We'd like a solution to still be able to autocomplete the properties on individual items (e.g. .id) via intellisense in editors while still being able to reference to the whole list.

Sidenote: Maps probably share a similar problem and we should also address that (separately).

@ansgarm ansgarm force-pushed the complex-lists-as-arrays branch 2 times, most recently from 1cc66e6 to 14724b2 Compare February 22, 2022 09:56
@ansgarm ansgarm added the ci/update-snapshots When set on a PR a GH Action will update and push all snapshot tests label Mar 3, 2022
@github-actions github-actions bot added ci/updating-snapshots CI is currently updating this PR with new snapshot tests and removed ci/update-snapshots When set on a PR a GH Action will update and push all snapshot tests ci/updating-snapshots CI is currently updating this PR with new snapshot tests labels Mar 3, 2022
@ansgarm ansgarm added the ci/update-snapshots When set on a PR a GH Action will update and push all snapshot tests label Mar 3, 2022
@github-actions github-actions bot added ci/updating-snapshots CI is currently updating this PR with new snapshot tests and removed ci/update-snapshots When set on a PR a GH Action will update and push all snapshot tests ci/updating-snapshots CI is currently updating this PR with new snapshot tests labels Mar 3, 2022
@vercel
Copy link

vercel bot commented Mar 4, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hashicorp/terraform-cdk/B1BSvD7YrBKmvQYRfMP2MQhsNmXa
✅ Preview: https://terraform-cdk-git-complex-lists-as-arrays-hashicorp.vercel.app

[Deployment for 3e579d4 canceled]

@ansgarm ansgarm merged commit 075fc30 into main Mar 17, 2022
@ansgarm ansgarm deleted the complex-lists-as-arrays branch March 17, 2022 16:14
@github-actions
Copy link
Contributor

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.

@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace ComplexComputedList with native array with a single ComplexComputedObject
4 participants