lang/funcs: Conversion functions can handle sensitive values #28446
+56
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In order to avoid updating every one of our existing functions with explicit support for sensitive values, there's a default rule in the
functions system which makes the result of a function sensitive if any of its arguments contain sensitive values.
We were applying that default to the various type conversion functions, like
tomap
andtolist
, which meant that converting a complex-typed value with a sensitive value anywhere inside it would result in a wholly-sensitive result.That's unnecessarily conservative because the
cty
conversion layer (which these functions are wrapping) already knows how to handle sensitivity in a more precise way. Therefore we can opt in to handling marked values (which Terraform uses for sensitivity) here and the only special thing we need to do is handle errors related to sensitive values differently, so we won't print their values out literally in case of an error (and so that the attempt to print them out literally won't panic trying to extract the marked values).The more-conservative-than-needed sensitivity here was mainly just a cosmetic annoyance, but it has a more practical implication when using
tomap
ortoset
to prepare a partially-sensitive collection for use infor_each
:Without this PR, the
for_each
innull_resource.example
is invalid because the whole map is marked as sensitive. After this PR it works because the map itself is known and onlylocal.sensitive_parts["beep"]
returns an unknown value.