-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: validate node name * fix: duplicate imports
- Loading branch information
1 parent
7c91155
commit 21d0e9e
Showing
6 changed files
with
95 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package node | ||
|
||
import ( | ||
pveAPI "github.com/Telmate/proxmox-api-go/proxmox" | ||
|
||
"github.com/hashicorp/go-cty/cty" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const ( | ||
RootNode string = "target_node" | ||
RootNodes string = "target_nodes" | ||
) | ||
|
||
func SchemaNode(s schema.Schema, guestType string) *schema.Schema { | ||
s.Type = schema.TypeString | ||
s.Description = "The node the " + guestType + " guest goes to." | ||
s.ValidateDiagFunc = func(i interface{}, path cty.Path) diag.Diagnostics { | ||
v, ok := i.(string) | ||
if !ok { | ||
return diag.Diagnostics{diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "Invalid " + RootNode, | ||
Detail: RootNode + " must be a string", | ||
AttributePath: path}} | ||
} | ||
if err := pveAPI.NodeName(v).Validate(); err != nil { | ||
return diag.Diagnostics{diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "Invalid " + RootNode, | ||
AttributePath: path}} | ||
} | ||
return nil | ||
} | ||
return &s | ||
} | ||
|
||
func SchemaNodes() *schema.Schema { | ||
return &schema.Schema{ | ||
Type: schema.TypeList, // TODO should be `schema.TypeSet` | ||
Optional: true, | ||
Description: "A list of nodes the qemu guest goes to.", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics { | ||
v, ok := i.(string) | ||
if !ok { | ||
return diag.Diagnostics{diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "Invalid " + RootNodes, | ||
Detail: RootNodes + " must be a string", | ||
AttributePath: path}} | ||
} | ||
if err := pveAPI.NodeName(v).Validate(); err != nil { | ||
return diag.Diagnostics{diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "Invalid " + RootNodes, | ||
AttributePath: path}} | ||
} | ||
return nil | ||
}}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters