Skip to content

Commit

Permalink
attr: Added IsNull() and IsUnknown() methods to the Value inter…
Browse files Browse the repository at this point in the history
…face type

Reference: #193
  • Loading branch information
bflad committed Oct 1, 2021
1 parent 4b382e2 commit cdb2dcf
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changelog/pending.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:breaking-change
attr: The `Value` interface type now requires `IsNull() bool` and `IsUnknown() bool` methods for implementations.
```

```release-note:enhancement
attr: Added `IsNull()` and `IsUnknown()` methods to the `Value` interface type
```
6 changes: 6 additions & 0 deletions attr/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ type Value interface {
// Equal must return true if the Value is considered semantically equal
// to the Value passed as an argument.
Equal(Value) bool

// IsNull returns true if the Value is null.
IsNull() bool

// IsUnknown returns true if the Value is unknown.
IsUnknown() bool
}
10 changes: 10 additions & 0 deletions types/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ func (b Bool) Equal(other attr.Value) bool {
}
return b.Value == o.Value
}

// IsNull returns true if the Bool is null.
func (b Bool) IsNull() bool {
return b.Null
}

// IsUnknown returns true if the Bool is unknown.
func (b Bool) IsUnknown() bool {
return b.Unknown
}
10 changes: 10 additions & 0 deletions types/float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func (f Float64) Equal(other attr.Value) bool {
return f.Value == o.Value
}

// IsNull returns true if the Float64 is null.
func (f Float64) IsNull() bool {
return f.Null
}

// IsUnknown returns true if the Float64 is unknown.
func (f Float64) IsUnknown() bool {
return f.Unknown
}

// ToTerraformValue returns the data contained in the Float64 as a float64.
// If Unknown is true, it returns a tftypes.UnknownValue. If Null is true, it
// returns nil.
Expand Down
10 changes: 10 additions & 0 deletions types/int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ func (i Int64) Equal(other attr.Value) bool {
return i.Value == o.Value
}

// IsNull returns true if the Int64 is null.
func (i Int64) IsNull() bool {
return i.Null
}

// IsUnknown returns true if the Int64 is unknown.
func (i Int64) IsUnknown() bool {
return i.Unknown
}

// ToTerraformValue returns the data contained in the Int64 as a int64.
// If Unknown is true, it returns a tftypes.UnknownValue. If Null is true, it
// returns nil.
Expand Down
10 changes: 10 additions & 0 deletions types/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,13 @@ func (l List) Equal(o attr.Value) bool {
}
return true
}

// IsNull returns true if the List is null.
func (l List) IsNull() bool {
return l.Null
}

// IsUnknown returns true if the List is unknown.
func (l List) IsUnknown() bool {
return l.Unknown
}
10 changes: 10 additions & 0 deletions types/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,13 @@ func (m Map) Equal(o attr.Value) bool {
}
return true
}

// IsNull returns true if the Map is null.
func (m Map) IsNull() bool {
return m.Null
}

// IsUnknown returns true if the Map is unknown.
func (m Map) IsUnknown() bool {
return m.Unknown
}
10 changes: 10 additions & 0 deletions types/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,13 @@ func (n Number) Equal(other attr.Value) bool {
}
return n.Value.Cmp(o.Value) == 0
}

// IsNull returns true if the Number is null.
func (n Number) IsNull() bool {
return n.Null
}

// IsUnknown returns true if the Number is unknown.
func (n Number) IsUnknown() bool {
return n.Unknown
}
10 changes: 10 additions & 0 deletions types/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,13 @@ func (o Object) Equal(c attr.Value) bool {

return true
}

// IsNull returns true if the Object is null.
func (o Object) IsNull() bool {
return o.Null
}

// IsUnknown returns true if the Object is unknown.
func (o Object) IsUnknown() bool {
return o.Unknown
}
10 changes: 10 additions & 0 deletions types/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ func (s Set) Equal(o attr.Value) bool {
return true
}

// IsNull returns true if the Set is null.
func (s Set) IsNull() bool {
return s.Null
}

// IsUnknown returns true if the Set is unknown.
func (s Set) IsUnknown() bool {
return s.Unknown
}

func (s Set) contains(v attr.Value) bool {
for _, elem := range s.Elems {
if elem.Equal(v) {
Expand Down
10 changes: 10 additions & 0 deletions types/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ func (s String) Equal(other attr.Value) bool {
}
return s.Value == o.Value
}

// IsNull returns true if the String is null.
func (s String) IsNull() bool {
return s.Null
}

// IsUnknown returns true if the String is unknown.
func (s String) IsUnknown() bool {
return s.Unknown
}

0 comments on commit cdb2dcf

Please sign in to comment.