Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Dec 25, 2024
1 parent a81af42 commit d87da76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
32 changes: 16 additions & 16 deletions spectrocloud/cluster_common_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,18 @@ func toBackupPolicy(d *schema.ResourceData) *models.V1ClusterBackupConfig {
}
}

//include := true
//if policy["include_cluster_resources"] != nil {
// include = policy["include_cluster_resources"].(bool)
//}

// Extract and process the policy settings
includeClusterResourceMode := models.V1IncludeClusterResourceMode("Always") // Default value
includeClusterResourceMode := models.V1IncludeClusterResourceMode("Auto") // Default value
if policy["include_cluster_resources_mode"] != "" {
if v, ok := policy["include_cluster_resources_mode"].(string); ok {
switch strings.ToLower(v) {
case "always":
includeClusterResourceMode = models.V1IncludeClusterResourceMode("Always")
case "never":
includeClusterResourceMode = models.V1IncludeClusterResourceMode("Never")
case "auto":
includeClusterResourceMode = models.V1IncludeClusterResourceMode("Auto")
}
includeClusterResourceMode = convertIncludeResourceMode(v)
}
} else if policy["include_cluster_resources"] != nil {
if include, ok := policy["include_cluster_resources"].(bool); ok {
if include {
includeClusterResourceMode = models.V1IncludeClusterResourceMode("Always")
includeClusterResourceMode = convertIncludeResourceMode("Always")
} else {
includeClusterResourceMode = models.V1IncludeClusterResourceMode("Never")
includeClusterResourceMode = convertIncludeResourceMode("Never")
}
}
}
Expand All @@ -71,6 +59,18 @@ func toBackupPolicy(d *schema.ResourceData) *models.V1ClusterBackupConfig {
return nil
}

func convertIncludeResourceMode(m string) (mode models.V1IncludeClusterResourceMode) {
switch strings.ToLower(m) {
case "always":
return models.V1IncludeClusterResourceMode("Always")
case "never":
return models.V1IncludeClusterResourceMode("Never")
case "auto":
return models.V1IncludeClusterResourceMode("Auto")
}
return ""
}

func flattenBackupPolicy(policy *models.V1ClusterBackupConfig) []interface{} {
result := make([]interface{}, 0, 1)
data := make(map[string]interface{})
Expand Down
5 changes: 2 additions & 3 deletions spectrocloud/schemas/backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ func BackupPolicySchema() *schema.Schema {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Whether to include the cluster resources in the backup. If set to false, only the cluster configuration and disks will be backed up. (Note: Starting with Palette version 4.6, the `include_cluster_resources` attribute will be changed to a string type, supporting the values `always`, `never`, and `auto`.)",
Description: "Indicates whether to include cluster resources in the backup. If set to false, only the cluster configuration and disks will be backed up. (Note: Starting with Palette version 4.6, the include_cluster_resources attribute will be deprecated, and a new attribute, include_cluster_resources_mode, will be introduced.)",
},
"include_cluster_resources_mode": {
Type: schema.TypeString,
Optional: true,
Default: nil,
Description: "Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. (Note: Starting with Palette version 4.6, the `include_cluster_resources` attribute will be changed to a string type, supporting these values.)",
Description: "Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`.",
ValidateFunc: validation.StringInSlice([]string{"always", "never", "auto"}, false),
},
"namespaces": {
Expand Down

0 comments on commit d87da76

Please sign in to comment.