nonsensitive: no longer produces error when applied to nonsensitive values (#33856)

* Proposing fix to #31693 (not always possible to apply nonsensitive)

https://github.com/hashicorp/terraform/issues/31693

* hashicorp#31693 not always possible to apply nonsensitive

updated documentation

* Update sensitive_test.go

Fixing tests

* Corrections as per https://github.com/hashicorp/terraform/pull/33856#discussion_r1330042125
pull/34738/head
Joao C Costa 3 years ago committed by GitHub
parent 7e34ef8b81
commit 47beda901e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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

@ -73,10 +73,8 @@ due to an inappropriate call to `nonsensitive` in your module, that's a bug in
your module and not a bug in Terraform 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
or misleading to a future maintainer of your module. Use `nonsensitive` only
after careful consideration and with definite intent.
`nonsensitive` will make no changes to values that aren't marked as sensitive, even though such a call may be redundant and potentially confusing.
Use `nonsensitive` only after careful consideration and with definite intent.
Consider including a comment adjacent to your call to explain to future
maintainers what makes the usage safe and thus what invariants they must take

Loading…
Cancel
Save