diff --git a/spectrocloud/cluster_common_policies.go b/spectrocloud/cluster_common_policies.go index 88d8324a..d9440984 100644 --- a/spectrocloud/cluster_common_policies.go +++ b/spectrocloud/cluster_common_policies.go @@ -2,10 +2,10 @@ package spectrocloud import ( "errors" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/spectrocloud/palette-sdk-go/api/models" "github.com/spectrocloud/palette-sdk-go/client" + "strings" ) func toPolicies(d *schema.ResourceData) *models.V1SpectroClusterPolicies { @@ -28,18 +28,41 @@ func toBackupPolicy(d *schema.ResourceData) *models.V1ClusterBackupConfig { } } - include := true - if policy["include_cluster_resources"] != nil { - include = policy["include_cluster_resources"].(bool) + //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 + 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") + } + } + } else if policy["include_cluster_resources"] != nil { + if include, ok := policy["include_cluster_resources"].(bool); ok { + if include { + includeClusterResourceMode = models.V1IncludeClusterResourceMode("Always") + } else { + includeClusterResourceMode = models.V1IncludeClusterResourceMode("Never") + } + } } return &models.V1ClusterBackupConfig{ - BackupLocationUID: policy["backup_location_id"].(string), - BackupPrefix: policy["prefix"].(string), - DurationInHours: int64(policy["expiry_in_hour"].(int)), - IncludeAllDisks: policy["include_disks"].(bool), - IncludeClusterResources: include, - Namespaces: namespaces, + BackupLocationUID: policy["backup_location_id"].(string), + BackupPrefix: policy["prefix"].(string), + DurationInHours: int64(policy["expiry_in_hour"].(int)), + IncludeAllDisks: policy["include_disks"].(bool), + IncludeClusterResourceMode: includeClusterResourceMode, + Namespaces: namespaces, Schedule: &models.V1ClusterFeatureSchedule{ ScheduledRunTime: policy["schedule"].(string), }, @@ -58,6 +81,7 @@ func flattenBackupPolicy(policy *models.V1ClusterBackupConfig) []interface{} { data["expiry_in_hour"] = policy.DurationInHours data["include_disks"] = policy.IncludeAllDisks data["include_cluster_resources"] = policy.IncludeClusterResources + data["include_cluster_resources_mode"] = policy.IncludeClusterResourceMode result = append(result, data) return result } diff --git a/spectrocloud/schemas/backup_policy.go b/spectrocloud/schemas/backup_policy.go index 77d981d2..357747fc 100644 --- a/spectrocloud/schemas/backup_policy.go +++ b/spectrocloud/schemas/backup_policy.go @@ -1,6 +1,9 @@ package schemas -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) func BackupPolicySchema() *schema.Schema { return &schema.Schema{ @@ -42,6 +45,13 @@ func BackupPolicySchema() *schema.Schema { 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`.)", }, + "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.)", + ValidateFunc: validation.StringInSlice([]string{"always", "never", "auto"}, false), + }, "namespaces": { Type: schema.TypeSet, Optional: true,