Skip to content

Conversation

@stephybun
Copy link
Member

@stephybun stephybun commented Aug 19, 2025

Description

  • Adds a new public package with functions that convert a cty value to a tftypes value
  • Adds two receiver functions on ResourceData that convert resource identity or resource data in cty to tftypes

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

None

@stephybun stephybun force-pushed the f/convert-cty-to-tftype branch 3 times, most recently from cb7d9ba to fc84332 Compare August 21, 2025 09:34
@stephybun stephybun marked this pull request as ready for review August 22, 2025 10:55
@stephybun stephybun requested a review from a team as a code owner August 22, 2025 10:55
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @stephybun ! I have a couple questions and comments but overall all the code is looking good 👍🏻

@stephybun stephybun requested a review from austinvalle August 25, 2025 12:23
@stephybun stephybun force-pushed the f/convert-cty-to-tftype branch from 7eabc12 to 9419032 Compare August 26, 2025 07:42
austinvalle
austinvalle previously approved these changes Aug 27, 2025
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Left 2 comments, but neither are deal breakers for what you're looking to merge here. I do think the unknown one should be addressed at some point 👍🏻

Comment on lines 19 to 21
if in.IsNull() || !in.IsKnown() {
return nullTfValue(primitiveType), nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for all of the other functions

If it's unknown, we should send back an unknown value instead of null. State should never have an unknown value in it, so this might be a moot point, but if we have any bugs in how the resource data is setup, we want to make sure we don't obfuscate the data 🙂

You can create an unknown value in tftypes like so:

tftypes.NewValue(ty, tftypes.UnknownValue)

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package convert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for completeness, I'd add some tests here for null/unknown values.

Maybe a test for dynamic pseudo type in primitives (which would be an unknown dynamic and a null dynamic)

@stephybun stephybun force-pushed the f/convert-cty-to-tftype branch from 65b3247 to 6590c69 Compare August 28, 2025 09:25
"breed": tftypes.NewValue(tftypes.String, "Golden"),
"weight": tftypes.NewValue(tftypes.Number, 30),
"toys": tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, []tftypes.Value{
tftypes.NewValue(tftypes.String, "dummy"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bobby over here playing with dummies 😮

Comment on lines +368 to +369
"ananas": tftypes.NewValue(tftypes.String, "pineapple"),
"erdbeere": tftypes.NewValue(tftypes.String, "strawberry"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun lesson in German

Copy link
Contributor

@rainkwan rainkwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the changes should address previous comments so LGTM 👍🏽

@stephybun stephybun merged commit f982e31 into main Aug 28, 2025
23 checks passed
@stephybun stephybun deleted the f/convert-cty-to-tftype branch August 28, 2025 15:54
stephybun added a commit that referenced this pull request Sep 15, 2025
stephybun added a commit that referenced this pull request Sep 15, 2025
@austinvalle austinvalle added this to the v2.38.0 milestone Sep 16, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2025
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.

3 participants