nonsensitive no longer produces error when applied to values that are not sensitive (#369)

Signed-off-by: Joao C Costa <joao.costa@kit-ar.com>
This commit is contained in:
Joao C Costa 2023-12-27 14:16:13 +00:00 committed by GitHub
parent 55651dca33
commit 28e6bce155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 10 deletions

View File

@ -10,6 +10,7 @@ ENHANCEMENTS:
BUG FIXES:
* `tofu test` resources cleanup at the end of tests changed to use simple reverse run block order. ([#1043](https://github.com/opentofu/opentofu/pull/1043))
* nonsensitive no longer produces error when applied to values that are not sensitive
## Previous Releases

View File

@ -52,9 +52,6 @@ var NonsensitiveFunc = function.New(&function.Spec{
return args[0].Type(), nil
},
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
if args[0].IsKnown() && !args[0].HasMark(marks.Sensitive) {
return cty.DynamicVal, function.NewArgErrorf(0, "the given value is not sensitive, so this call is redundant")
}
v, m := args[0].Unmark()
delete(m, marks.Sensitive) // remove the sensitive marking
return v.WithMarks(m), nil

View File

@ -130,16 +130,16 @@ func TestNonsensitive(t *testing.T) {
``,
},
// Passing a value that is already non-sensitive is an error,
// because this function should always be used with specific
// intention, not just as a "make everything visible" hammer.
// Passing a value that is already non-sensitive is not an error,
// as this function may be used with specific to ensure that all
// values are indeed non-sensitive
{
cty.NumberIntVal(1),
`the given value is not sensitive, so this call is redundant`,
``,
},
{
cty.NullVal(cty.String),
`the given value is not sensitive, so this call is redundant`,
``,
},
// Unknown values may become sensitive once they are known, so we

View File

@ -73,8 +73,8 @@ due to an inappropriate call to `nonsensitive` in your module, that's a bug in
your module and not a bug in OpenTofu itself.
**Use this function sparingly and only with due care.**
`nonsensitive` will return an error if you pass a value that isn't marked
as sensitive, because such a call would be redundant and potentially confusing
`nonsensitive` will no longer return an error if you pass a value that isn't marked
as sensitive, even though such a call may be redundant and potentially confusing
or misleading to a future maintainer of your module. Use `nonsensitive` only
after careful consideration and with definite intent.