Skip to content

Commit 2dead29

Browse files
committed
add validation
1 parent 5db4494 commit 2dead29

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

internal/services/instance/server.go

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

internal/verify/uuid.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ 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+
56+
if uuid == "" {
57+
return nil
58+
}
59+
60+
if !validation.IsUUID(uuid) {
61+
return diag.Diagnostics{diag.Diagnostic{
62+
Severity: diag.Error,
63+
Summary: "invalid UUID: " + uuid,
64+
AttributePath: path,
65+
Detail: "format should be 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' (36) and contains valid hexadecimal characters",
66+
}}
67+
}
68+
69+
return nil
70+
}
71+
}
72+
4573
func IsUUIDWithLocality() schema.SchemaValidateDiagFunc {
4674
return func(value any, path cty.Path) diag.Diagnostics {
4775
uuid, isString := value.(string)

0 commit comments

Comments
 (0)