Skip to content

Commit 3dce383

Browse files
committed
add validation
1 parent 7bd6633 commit 3dce383

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

internal/services/instance/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,10 @@ func ResourceServer() *schema.Resource {
373373
},
374374
},
375375
"admin_password_encryption_ssh_key_id": {
376-
Type: schema.TypeString,
377-
Optional: true,
378-
Description: "The ID of the IAM SSH key used to encrypt the initial admin password on a Windows server",
376+
Type: schema.TypeString,
377+
Optional: true,
378+
ValidateDiagFunc: verify.IsUUIDOrEmpty(),
379+
Description: "The ID of the IAM SSH key used to encrypt the initial admin password on a Windows server",
379380
},
380381
"zone": zonal.Schema(),
381382
"organization_id": account.OrganizationIDSchema(),

internal/verify/uuid.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ func IsUUID() schema.SchemaValidateDiagFunc {
4242
}
4343
}
4444

45+
func IsUUIDOrEmpty() schema.SchemaValidateDiagFunc {
46+
return func(value any, path cty.Path) diag.Diagnostics {
47+
uuid, isString := value.(string)
48+
if !isString {
49+
return diag.Diagnostics{diag.Diagnostic{
50+
Severity: diag.Error,
51+
Summary: "invalid UUID not a string",
52+
AttributePath: path,
53+
}}
54+
}
55+
if uuid == "" {
56+
return nil
57+
}
58+
59+
if !validation.IsUUID(uuid) {
60+
return diag.Diagnostics{diag.Diagnostic{
61+
Severity: diag.Error,
62+
Summary: "invalid UUID: " + uuid,
63+
AttributePath: path,
64+
Detail: "format should be 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' (36) and contains valid hexadecimal characters",
65+
}}
66+
}
67+
68+
return nil
69+
}
70+
}
71+
4572
func IsUUIDWithLocality() schema.SchemaValidateDiagFunc {
4673
return func(value any, path cty.Path) diag.Diagnostics {
4774
uuid, isString := value.(string)

0 commit comments

Comments
 (0)