diff --git a/docs/resources/cluster_aks.md b/docs/resources/cluster_aks.md index 6c281a41..d56c46cc 100644 --- a/docs/resources/cluster_aks.md +++ b/docs/resources/cluster_aks.md @@ -228,7 +228,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_aws.md b/docs/resources/cluster_aws.md index 3c022ea9..9707e999 100644 --- a/docs/resources/cluster_aws.md +++ b/docs/resources/cluster_aws.md @@ -255,7 +255,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_azure.md b/docs/resources/cluster_azure.md index d2f5c97e..74ea77f4 100644 --- a/docs/resources/cluster_azure.md +++ b/docs/resources/cluster_azure.md @@ -237,7 +237,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_custom_cloud.md b/docs/resources/cluster_custom_cloud.md index 88d9732c..af88c0bc 100644 --- a/docs/resources/cluster_custom_cloud.md +++ b/docs/resources/cluster_custom_cloud.md @@ -220,7 +220,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_edge_native.md b/docs/resources/cluster_edge_native.md index f287fd28..9f5633fd 100644 --- a/docs/resources/cluster_edge_native.md +++ b/docs/resources/cluster_edge_native.md @@ -200,7 +200,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_edge_vsphere.md b/docs/resources/cluster_edge_vsphere.md index 8508a137..65ea25af 100644 --- a/docs/resources/cluster_edge_vsphere.md +++ b/docs/resources/cluster_edge_vsphere.md @@ -156,7 +156,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_eks.md b/docs/resources/cluster_eks.md index 565b0d5f..634f32c7 100644 --- a/docs/resources/cluster_eks.md +++ b/docs/resources/cluster_eks.md @@ -219,7 +219,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_gcp.md b/docs/resources/cluster_gcp.md index 1bc5d4da..65331782 100644 --- a/docs/resources/cluster_gcp.md +++ b/docs/resources/cluster_gcp.md @@ -189,7 +189,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_gke.md b/docs/resources/cluster_gke.md index e8caa13a..c28a89da 100644 --- a/docs/resources/cluster_gke.md +++ b/docs/resources/cluster_gke.md @@ -170,7 +170,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_maas.md b/docs/resources/cluster_maas.md index 7350d112..4a75bbde 100644 --- a/docs/resources/cluster_maas.md +++ b/docs/resources/cluster_maas.md @@ -236,7 +236,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_openstack.md b/docs/resources/cluster_openstack.md index c62cd4bd..2ceb6a6f 100644 --- a/docs/resources/cluster_openstack.md +++ b/docs/resources/cluster_openstack.md @@ -194,7 +194,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_tke.md b/docs/resources/cluster_tke.md index 609abce1..c98d3a65 100644 --- a/docs/resources/cluster_tke.md +++ b/docs/resources/cluster_tke.md @@ -126,7 +126,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/cluster_vsphere.md b/docs/resources/cluster_vsphere.md index 5b194726..de286868 100644 --- a/docs/resources/cluster_vsphere.md +++ b/docs/resources/cluster_vsphere.md @@ -160,7 +160,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/virtual_cluster.md b/docs/resources/virtual_cluster.md index f8ee1870..2037f2ff 100644 --- a/docs/resources/virtual_cluster.md +++ b/docs/resources/virtual_cluster.md @@ -100,7 +100,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/docs/resources/workspace.md b/docs/resources/workspace.md index 6da5e9fb..bcdfccd0 100644 --- a/docs/resources/workspace.md +++ b/docs/resources/workspace.md @@ -140,7 +140,8 @@ Optional: - `cluster_uids` (Set of String) The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included. - `include_all_clusters` (Boolean) Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included. -- `include_cluster_resources` (Boolean) 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` (Boolean) 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` (String) Specifies whether to include the cluster resources in the backup. Supported values are `always`, `never`, and `auto`. - `include_disks` (Boolean) Whether to include the disks in the backup. If set to false, only the cluster configuration will be backed up. - `namespaces` (Set of String) The list of Kubernetes namespaces to include in the backup. If not specified, all namespaces will be included. diff --git a/spectrocloud/cluster_common_policies.go b/spectrocloud/cluster_common_policies.go index 88d8324a..7b08cdb8 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,29 @@ 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("Auto") // Default value + if policy["include_cluster_resources_mode"] != "" { + if v, ok := policy["include_cluster_resources_mode"].(string); ok { + includeClusterResourceMode = convertIncludeResourceMode(v) + } + } else if policy["include_cluster_resources"] != nil { + if include, ok := policy["include_cluster_resources"].(bool); ok { + if include { + includeClusterResourceMode = convertIncludeResourceMode("Always") + } else { + includeClusterResourceMode = convertIncludeResourceMode("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), }, @@ -48,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{}) @@ -57,11 +80,16 @@ func flattenBackupPolicy(policy *models.V1ClusterBackupConfig) []interface{} { data["namespaces"] = policy.Namespaces data["expiry_in_hour"] = policy.DurationInHours data["include_disks"] = policy.IncludeAllDisks - data["include_cluster_resources"] = policy.IncludeClusterResources + data["include_cluster_resources"] = flattenIncludeResourceMode(policy.IncludeClusterResourceMode) + data["include_cluster_resources_mode"] = policy.IncludeClusterResourceMode result = append(result, data) return result } +func flattenIncludeResourceMode(m models.V1IncludeClusterResourceMode) bool { + return m == models.V1IncludeClusterResourceMode("Always") +} + func updateBackupPolicy(c *client.V1Client, d *schema.ResourceData) error { if policy := toBackupPolicy(d); policy != nil { //clusterContext := d.Get("context").(string) diff --git a/spectrocloud/cluster_policies_test.go b/spectrocloud/cluster_policies_test.go index 64d605ef..e4bf4908 100644 --- a/spectrocloud/cluster_policies_test.go +++ b/spectrocloud/cluster_policies_test.go @@ -76,13 +76,14 @@ func TestFlattenBackupPolicy(t *testing.T) { expected := []interface{}{ map[string]interface{}{ - "schedule": "daily", - "backup_location_id": "location-123", - "prefix": "backup-prefix", - "namespaces": []string{"namespace1", "namespace2"}, - "expiry_in_hour": int64(24), - "include_disks": true, - "include_cluster_resources": true, + "schedule": "daily", + "backup_location_id": "location-123", + "prefix": "backup-prefix", + "namespaces": []string{"namespace1", "namespace2"}, + "expiry_in_hour": int64(24), + "include_disks": true, + "include_cluster_resources": false, + "include_cluster_resources_mode": models.V1IncludeClusterResourceMode(""), }, } @@ -112,12 +113,13 @@ func TestToBackupPolicy(t *testing.T) { result := toBackupPolicy(resourceData) expected := &models.V1ClusterBackupConfig{ - BackupLocationUID: "location-123", - BackupPrefix: "backup-prefix", - DurationInHours: 24, - IncludeAllDisks: true, - IncludeClusterResources: true, - Namespaces: []string{"namespace1"}, + BackupLocationUID: "location-123", + BackupPrefix: "backup-prefix", + DurationInHours: 24, + IncludeAllDisks: true, + IncludeClusterResources: false, + IncludeClusterResourceMode: models.V1IncludeClusterResourceMode("Always"), + Namespaces: []string{"namespace1"}, Schedule: &models.V1ClusterFeatureSchedule{ ScheduledRunTime: "daily", }, @@ -192,12 +194,13 @@ func TestToPolicies(t *testing.T) { expected := &models.V1SpectroClusterPolicies{ BackupPolicy: &models.V1ClusterBackupConfig{ - BackupLocationUID: "location-123", - BackupPrefix: "backup-prefix", - DurationInHours: 24, - IncludeAllDisks: true, - IncludeClusterResources: true, - Namespaces: []string{"namespace1"}, + BackupLocationUID: "location-123", + BackupPrefix: "backup-prefix", + DurationInHours: 24, + IncludeAllDisks: true, + IncludeClusterResources: false, + IncludeClusterResourceMode: models.V1IncludeClusterResourceMode("Always"), + Namespaces: []string{"namespace1"}, Schedule: &models.V1ClusterFeatureSchedule{ ScheduledRunTime: "daily", }, diff --git a/spectrocloud/schemas/backup_policy.go b/spectrocloud/schemas/backup_policy.go index 77d981d2..d337b449 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{ @@ -40,7 +43,13 @@ 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, + 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": { Type: schema.TypeSet,