Skip to content

Commit

Permalink
fix: validate cluster_type to ensure it is either 'k3s' or 'talos' (#279
Browse files Browse the repository at this point in the history
)

fix: validate cluster_type to ensure it is either 'k3s' or 'talos'
  • Loading branch information
Praveen005 authored Jul 23, 2024
1 parent 16c018b commit d55208f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
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

0 comments on commit d55208f

Please sign in to comment.