Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 893dd34

Browse files
feat(uuidtypes)!: adds support for the new attr.ValueState via [email protected].
1 parent 693bfe7 commit 893dd34

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

uuidtypes/uuid.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ var (
3535

3636
// UUIDNull returns a null UUID value.
3737
func UUIDNull() UUID {
38-
return UUID{null: true}
38+
return UUID{state: attr.ValueStateNull}
3939
}
4040

4141
// UUIDUnknown returns an unknown UUID value.
4242
func UUIDUnknown() UUID {
43-
return UUID{unknown: true}
43+
return UUID{state: attr.ValueStateUnknown}
4444
}
4545

4646
// UUIDFromString returns a value or any errors when attempting to parse the
@@ -61,6 +61,7 @@ func UUIDFromString(value string, schemaPath path.Path) (UUID, diag.Diagnostics)
6161
}
6262

6363
return UUID{
64+
state: attr.ValueStateKnown,
6465
value: validUUID,
6566
}, nil
6667
}
@@ -69,16 +70,16 @@ func UUIDFromString(value string, schemaPath path.Path) (UUID, diag.Diagnostics)
6970
// UUID Value.
7071
func UUIDFromGoogleUUID(value uuid.UUID) UUID {
7172
return UUID{
73+
state: attr.ValueStateKnown,
7274
value: value,
7375
}
7476
}
7577

7678
// UUID provides a concrete implementation of a UUID tftypes.Value for the
7779
// Terraform Plugin framework.
7880
type UUID struct {
79-
null bool
80-
unknown bool
81-
value uuid.UUID
81+
state attr.ValueState
82+
value uuid.UUID
8283
}
8384

8485
// Type returns the UUID type that created the UUID.
@@ -101,12 +102,12 @@ func (u UUID) ToTerraformValue(_ context.Context) (tftypes.Value, error) {
101102

102103
// IsNull returns true if the uuid represents a null value.
103104
func (u UUID) IsNull() bool {
104-
return u.null
105+
return u.state == attr.ValueStateNull
105106
}
106107

107108
// IsUnknown returns true if the uuid represents an unknown value.
108109
func (u UUID) IsUnknown() bool {
109-
return u.unknown
110+
return u.state == attr.ValueStateUnknown
110111
}
111112

112113
// Equal returns true if the uuid is semantically equal to the Value passed as
@@ -117,11 +118,7 @@ func (u UUID) Equal(other attr.Value) bool {
117118
return false
118119
}
119120

120-
if otherValue.null != u.null {
121-
return false
122-
}
123-
124-
if otherValue.unknown != u.unknown {
121+
if otherValue.state != u.state {
125122
return false
126123
}
127124

@@ -133,13 +130,14 @@ func (u UUID) Equal(other attr.Value) bool {
133130
// or UnknownValueString (`<unknown>`) when IsUnknown() returns true,
134131
// or NullValueString (`<null>`) when IsNull() return true.
135132
func (u UUID) String() string {
136-
if u.null {
133+
switch u.state {
134+
case attr.ValueStateNull:
137135
return attr.NullValueString
138-
}
139136

140-
if u.unknown {
137+
case attr.ValueStateUnknown:
141138
return attr.UnknownValueString
142-
}
143139

144-
return u.value.String()
140+
default:
141+
return u.value.String()
142+
}
145143
}

uuidtypes/uuid_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func TestUUID_Equal(t *testing.T) {
150150
{
151151
name: "not-uuidtypes.UUID",
152152
value: uuidtypes.UUIDFromGoogleUUID(uuid.MustParse(valueUUIDv4)),
153-
other: types.String{Value: valueUUIDv4},
153+
other: types.StringValue(valueUUIDv4),
154154
expected: false,
155155
},
156156
}

uuidtypes/uuid_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ func (u UUIDType) ValueFromTerraform(_ context.Context, value tftypes.Value) (at
113113

114114
// ValueType returns attr.Value type returned by ValueFromTerraform.
115115
func (u UUIDType) ValueType(context.Context) attr.Value {
116-
return UUID{}
116+
return UUIDNull()
117117
}

0 commit comments

Comments
 (0)