Skip to content

Commit 2840903

Browse files
committed
fix: mark invalid UUIDs as known
1 parent e90acf0 commit 2840903

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

internal/provider/uuid.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ func (t uuidType) ValueFromString(ctx context.Context, in basetypes.StringValue)
4848
return NewUUIDUnknown(), diags
4949
}
5050

51-
value, err := uuid.Parse(in.ValueString())
52-
if err != nil {
53-
// The framework doesn't want us to return validation errors here
54-
// for some reason. They get caught by `ValidateAttribute` instead,
55-
// and this function isn't called directly by our provider - UUIDValue
56-
// takes a valid UUID instead of a string.
57-
return NewUUIDUnknown(), diags
58-
}
59-
60-
return UUIDValue(value), diags
51+
// This function deliberately does not handle invalid UUIDs.
52+
// Instead, `ValidateAttribute` will be called
53+
// on the stored string during `validate` `plan` and `apply`,
54+
// which will also create an error diagnostic.
55+
// For that reason, storing the zero UUID is fine.
56+
v, _ := uuid.Parse(in.ValueString())
57+
return UUID{
58+
StringValue: in,
59+
value: v,
60+
}, diags
6161
}
6262

6363
// ValueFromTerraform implements basetypes.StringTypable.

internal/provider/uuid_internal_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/google/uuid"
88
"github.com/hashicorp/terraform-plugin-framework/attr"
99
"github.com/hashicorp/terraform-plugin-framework/types"
10+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1011
"github.com/hashicorp/terraform-plugin-go/tftypes"
1112
"github.com/stretchr/testify/require"
1213
)
@@ -37,9 +38,12 @@ func TestUUIDTypeValueFromTerraform(t *testing.T) {
3738
expected: UUIDValue(ValidUUID),
3839
},
3940
{
40-
name: "invalid UUID",
41-
input: tftypes.NewValue(tftypes.String, "invalid"),
42-
expected: NewUUIDUnknown(),
41+
name: "invalid UUID",
42+
input: tftypes.NewValue(tftypes.String, "invalid"),
43+
expected: UUID{
44+
StringValue: basetypes.NewStringValue("invalid"),
45+
value: uuid.Nil,
46+
},
4347
},
4448
}
4549

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy