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: 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)) * `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 ## Previous Releases

View File

@ -52,9 +52,6 @@ var NonsensitiveFunc = function.New(&function.Spec{
return args[0].Type(), nil return args[0].Type(), nil
}, },
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { 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() v, m := args[0].Unmark()
delete(m, marks.Sensitive) // remove the sensitive marking delete(m, marks.Sensitive) // remove the sensitive marking
return v.WithMarks(m), nil 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, // Passing a value that is already non-sensitive is not an error,
// because this function should always be used with specific // as this function may be used with specific to ensure that all
// intention, not just as a "make everything visible" hammer. // values are indeed non-sensitive
{ {
cty.NumberIntVal(1), cty.NumberIntVal(1),
`the given value is not sensitive, so this call is redundant`, ``,
}, },
{ {
cty.NullVal(cty.String), 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 // 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. your module and not a bug in OpenTofu itself.
**Use this function sparingly and only with due care.** **Use this function sparingly and only with due care.**
`nonsensitive` will return an error if you pass a value that isn't marked `nonsensitive` will no longer return an error if you pass a value that isn't marked
as sensitive, because such a call would be redundant and potentially confusing 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 or misleading to a future maintainer of your module. Use `nonsensitive` only
after careful consideration and with definite intent. after careful consideration and with definite intent.