Skip to content

Commit

Permalink
fix: OpenTofu crash with unknown value (#50)
Browse files Browse the repository at this point in the history
* OpenTofu (and only OpenTofu) passes zero values in place of unknowns
  when calling custom functions, and ignores the `AllowUnknownValues`
  parameter configuration.
  Besides being incorrect, misleading and resulting in unstable plans,
  this can also result in rogue nil pointers being embedded in custom
  function inputs and thus unexpected panics in the provider code.
  Amusingly the standard `v.IsNull()` function itself was triggering a
  nil-pointer deref 😭.
  We work around it by explicitly checking that all values aren't nil,
  but this is a temporary fix until the underlying issue can be resolved
  upstream in OpenTofu itself.

Refs: #48
  • Loading branch information
isometry authored Oct 30, 2024
1 parent d8bf59c commit 5d92347
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/helpers/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
)

func EncodeValue(v attr.Value) (any, error) {
if v.IsNull() {
// Avoid nil pointer deref with broken OpenTofu custom function
// implementation that passes unknown values as zero values.
if v == nil || v.IsNull() {
return nil, nil
}

Expand Down

0 comments on commit 5d92347

Please sign in to comment.