Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions internal/lang/funcs/sensitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions internal/lang/funcs/sensitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions website/docs/language/functions/nonsensitive.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down