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

Extend attr.Value interface to support IsFullyNullableKnown() #980

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion attr/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ type Value interface {
// IsNull returns true if the Value is not set, or is explicitly set to null.
IsNull() bool

// IsUnknown returns true if the value is not yet known.
// IsUnKnown returns true if the value is not yet known.
// If the value is an aggregate type, only the top level of the aggregate type
// is checked; elements and attributes are not checked.
IsUnknown() bool

// IsFullyNullableKnown returns true if the value is nullable known. If the value
// is an aggregate type, IsFullyNullableKnown only returns true if all elements
// and attributes are nullable known, as well.
IsFullyNullableKnown() bool

// String returns a summary representation of either the underlying Value,
// or UnknownValueString (`<unknown>`) when IsUnknown() returns true,
// or NullValueString (`<null>`) when IsNull() return true.
Expand Down
4 changes: 4 additions & 0 deletions internal/testing/testtypes/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (b Bool) IsUnknown() bool {
return b.Bool.IsUnknown()
}

func (b Bool) IsFullyNullableKnown() bool {
return b.Bool.IsFullyNullableKnown()
}

func (b Bool) String() string {
return b.Bool.String()
}
4 changes: 4 additions & 0 deletions internal/testing/testtypes/invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (i Invalid) IsUnknown() bool {
return false
}

func (i Invalid) IsFullyNullableKnown() bool {
return false
}

func (i Invalid) String() string {
return "<invalid>"
}
Expand Down
4 changes: 4 additions & 0 deletions internal/testing/testtypes/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,7 @@ func (n Number) IsNull() bool {
func (n Number) IsUnknown() bool {
return n.Number.IsUnknown()
}

func (n Number) IsFullyNullableKnown() bool {
return n.Number.IsFullyNullableKnown()
}
8 changes: 8 additions & 0 deletions internal/testing/testtypes/numberwithvalidateattribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (v NumberValueWithValidateAttributeError) IsUnknown() bool {
return v.InternalNumber.IsUnknown()
}

func (v NumberValueWithValidateAttributeError) IsFullyNullableKnown() bool {
return v.InternalNumber.IsFullyNullableKnown()
}

func (v NumberValueWithValidateAttributeError) String() string {
return v.InternalNumber.String()
}
Expand Down Expand Up @@ -145,6 +149,10 @@ func (v NumberValueWithValidateAttributeWarning) IsUnknown() bool {
return v.InternalNumber.IsUnknown()
}

func (v NumberValueWithValidateAttributeWarning) IsFullyNullableKnown() bool {
return v.InternalNumber.IsFullyNullableKnown()
}

func (v NumberValueWithValidateAttributeWarning) String() string {
return v.InternalNumber.String()
}
Expand Down
4 changes: 4 additions & 0 deletions internal/testing/testtypes/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (s String) IsUnknown() bool {
return s.InternalString.IsUnknown()
}

func (s String) IsFullyNullableKnown() bool {
return s.InternalString.IsFullyNullableKnown()
}

func (s String) String() string {
return s.InternalString.String()
}
8 changes: 8 additions & 0 deletions internal/testing/testtypes/stringwithvalidateattribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (v StringValueWithValidateAttributeError) IsUnknown() bool {
return v.InternalString.IsUnknown()
}

func (v StringValueWithValidateAttributeError) IsFullyNullableKnown() bool {
return v.InternalString.IsFullyNullableKnown()
}

func (v StringValueWithValidateAttributeError) String() string {
return v.InternalString.String()
}
Expand Down Expand Up @@ -145,6 +149,10 @@ func (v StringValueWithValidateAttributeWarning) IsUnknown() bool {
return v.InternalString.IsUnknown()
}

func (v StringValueWithValidateAttributeWarning) IsFullyNullableKnown() bool {
return v.InternalString.IsFullyNullableKnown()
}

func (v StringValueWithValidateAttributeWarning) String() string {
return v.InternalString.String()
}
Expand Down
4 changes: 4 additions & 0 deletions internal/testing/testtypes/stringwithvalidateparameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (v StringValueWithValidateParameterError) IsUnknown() bool {
return v.InternalString.IsUnknown()
}

func (v StringValueWithValidateParameterError) IsFullyNullableKnown() bool {
return v.InternalString.IsFullyNullableKnown()
}

func (v StringValueWithValidateParameterError) String() string {
return v.InternalString.String()
}
Expand Down
5 changes: 5 additions & 0 deletions types/basetypes/bool_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (b BoolValue) IsUnknown() bool {
return b.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Bool represents a currently nullable known value.
func (b BoolValue) IsFullyNullableKnown() bool {
return !b.IsUnknown()
}

// String returns a human-readable representation of the Bool value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
6 changes: 6 additions & 0 deletions types/basetypes/dynamic_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ func (v DynamicValue) IsUnknown() bool {
return v.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the DynamicValue's underlying value
// represents a currently nullable known value.
func (v DynamicValue) IsFullyNullableKnown() bool {
return v.value == nil || v.value.IsFullyNullableKnown()
}

// String returns a human-readable representation of the DynamicValue. The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
func (v DynamicValue) String() string {
Expand Down
5 changes: 5 additions & 0 deletions types/basetypes/float64_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func (f Float64Value) IsUnknown() bool {
return f.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Float64 represents a currently nullable known value.
func (f Float64Value) IsFullyNullableKnown() bool {
return !f.IsUnknown()
}

// String returns a human-readable representation of the Float64 value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
5 changes: 5 additions & 0 deletions types/basetypes/int64_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (i Int64Value) IsUnknown() bool {
return i.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Int64 represents a currently nullable known value.
func (i Int64Value) IsFullyNullableKnown() bool {
return !i.IsUnknown()
}

// String returns a human-readable representation of the Int64 value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
11 changes: 11 additions & 0 deletions types/basetypes/list_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ func (l ListValue) IsUnknown() bool {
return l.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the List represents a currently nullable known value,
// including all its elements, recursively.
func (l ListValue) IsFullyNullableKnown() bool {
for _, elem := range l.elements {
if !elem.IsFullyNullableKnown() {
return false
}
}
return true
}

// String returns a human-readable representation of the List value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
11 changes: 11 additions & 0 deletions types/basetypes/map_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ func (m MapValue) IsUnknown() bool {
return m.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Map represents a currently nullable known value,
// including all its elements, recursively.
func (m MapValue) IsFullyNullableKnown() bool {
for _, elem := range m.elements {
if !elem.IsFullyNullableKnown() {
return false
}
}
return true
}

// String returns a human-readable representation of the Map value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
5 changes: 5 additions & 0 deletions types/basetypes/missing_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (v missingValue) IsUnknown() bool {
return false
}

// IsFullyNullableKnown returns false.
func (v missingValue) IsFullyNullableKnown() bool {
return !v.IsUnknown()
}

// String returns a human-readable representation of the value.
//
// The string returned here is not protected by any compatibility guarantees,
Expand Down
5 changes: 5 additions & 0 deletions types/basetypes/number_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (n NumberValue) IsUnknown() bool {
return n.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Number represents a currently nullable known value.
func (n NumberValue) IsFullyNullableKnown() bool {
return !n.IsUnknown()
}

// String returns a human-readable representation of the Number value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
11 changes: 11 additions & 0 deletions types/basetypes/object_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,17 @@ func (o ObjectValue) IsUnknown() bool {
return o.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Object represents a currently nullable known value,
// including all its attributes, recursively.
func (o ObjectValue) IsFullyNullableKnown() bool {
for _, attr := range o.attributes {
if !attr.IsFullyNullableKnown() {
return false
}
}
return true
}

// String returns a human-readable representation of the Object value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
11 changes: 11 additions & 0 deletions types/basetypes/set_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ func (s SetValue) IsUnknown() bool {
return s.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Set represents a currently nullable known value,
// including all its elements, recursively.
func (s SetValue) IsFullyNullableKnown() bool {
for _, elem := range s.elements {
if !elem.IsFullyNullableKnown() {
return false
}
}
return true
}

// String returns a human-readable representation of the Set value.
// The string returned here is not protected by any compatibility guarantees,
// and is intended for logging and error reporting.
Expand Down
5 changes: 5 additions & 0 deletions types/basetypes/string_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func (s StringValue) IsUnknown() bool {
return s.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the String represents a currently nullable known value.
func (s StringValue) IsFullyNullableKnown() bool {
return s.state != attr.ValueStateUnknown
}

// String returns a human-readable representation of the String value. Use
// the ValueString method for Terraform data handling instead.
//
Expand Down
11 changes: 11 additions & 0 deletions types/basetypes/tuple_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ func (v TupleValue) IsUnknown() bool {
return v.state == attr.ValueStateUnknown
}

// IsFullyNullableKnown returns true if the Tuple represents a currently nullable known value,
// including all its elements, recursively.
func (v TupleValue) IsFullyNullableKnown() bool {
for _, elem := range v.elements {
if !elem.IsFullyNullableKnown() {
return false
}
}
return true
}

// String returns a human-readable representation of the Tuple. The string returned here is not protected by any
// compatibility guarantees, and is intended for logging and error reporting.
func (v TupleValue) String() string {
Expand Down