Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate cluster_type to ensure it is either 'k3s' or 'talos' #279

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions civo/kubernetes/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ func ResourceKubernetesCluster() *schema.Resource {
Description: "The existing firewall ID to use for this cluster",
},
"cluster_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The type of cluster to create, valid options are `k3s` or `talos` the default is `k3s`",
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The type of cluster to create, valid options are `k3s` or `talos` the default is `k3s`",
ValidateDiagFunc: utils.ValidateClusterType,
},
// Computed resource
"installed_applications": applicationSchema(),
Expand Down
15 changes: 15 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ func InPool(id string, list []civogo.KubernetesClusterPoolConfig) bool {
return false
}

// ValidateClusterType Validates if the user has provided a supported cluster type.
func ValidateClusterType(v interface{}, path cty.Path) diag.Diagnostics {
val := v.(string)
var diags diag.Diagnostics
if val != "k3s" && val != "talos" {

diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Invalid Cluster Type",
Detail: "The specified cluster type is invalid. Please choose either 'k3s' or 'talos'.",
})
}
return diags
}

// CustomError captures a specific portion of the full API error
type CustomError struct {
Code string `json:"code"`
Expand Down
Loading