Skip to content

Commit

Permalink
Merge pull request #340 from vmware/mshobha/scope-backup-schedule
Browse files Browse the repository at this point in the history
Add scope block support for backup schedule
  • Loading branch information
shobha2626 authored Nov 17, 2023
2 parents b0655a2 + ee06cb5 commit 4d323d0
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 196 deletions.
51 changes: 37 additions & 14 deletions docs/data-sources/backup_schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Listing target locations by cluster scope is supported only for clusters enabled

```terraform
data "tanzu-mission-control_backup_schedule" "demo" {
name = "BACKUP_SCHEDULE_NAME"
scope {
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
name = "TARGET_LOCATION_NAME"
cluster {
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
}
}
query = "QUERY"
Expand All @@ -32,11 +34,12 @@ data "tanzu-mission-control_backup_schedule" "demo" {
### Required

- `scope` (Block List, Min: 1, Max: 1) Search scope block (see [below for nested schema](#nestedblock--scope))
- `name` (String) The name of the backup schedule

### Optional

- `include_total_count` (Boolean) Whether to include total count of backups.
(Default: True)
(Default: True)
- `query` (String) Define a query for listing backups
- `sort_by` (String) Sort backups by field.

Expand All @@ -49,28 +52,30 @@ data "tanzu-mission-control_backup_schedule" "demo" {
<a id="nestedblock--scope"></a>
### Nested Schema for `scope`

Required:
Optional:

- `cluster_name` (String) Cluster name
- `cluster` (Block List, Max: 1) Cluster scope block (see [below for nested schema](#nestedblock--scope--cluster))

Optional:
<a id="nestedblock--scope--cluster"></a>
### Nested Schema for `scope.cluster`

Required:

- `cluster_name` (String) Cluster name
- `management_cluster_name` (String) Management cluster name
- `name` (String) The name of the backup schedule
- `provisioner_name` (String) Cluster provisioner name



<a id="nestedatt--schedules"></a>
### Nested Schema for `schedules`

Read-Only:

- `cluster_name` (String)
- `management_cluster_name` (String)
- `meta` (List of Object) (see [below for nested schema](#nestedobjatt--schedules--meta))
- `name` (String)
- `provisioner_name` (String)
- `scope` (String)
- `backup_scope` (String)
- `meta` (List of Object) (see [below for nested schema](#nestedobjatt--schedules--meta))
- `scope` (List of Object) (see [below for nested schema](#nestedobjatt--schedules--scope))
- `spec` (List of Object) (see [below for nested schema](#nestedobjatt--schedules--spec))

<a id="nestedobjatt--schedules--meta"></a>
Expand All @@ -85,6 +90,24 @@ Read-Only:
- `uid` (String)


<a id="nestedobjatt--schedules--scope"></a>
### Nested Schema for `schedules.scope`

Read-Only:

- `cluster` (List of Object) (see [below for nested schema](#nestedobjatt--schedules--scope--cluster))

<a id="nestedobjatt--schedules--scope--cluster"></a>
### Nested Schema for `schedules.scope.cluster`

Read-Only:

- `cluster_name` (String)
- `management_cluster_name` (String)
- `provisioner_name` (String)



<a id="nestedobjatt--schedules--spec"></a>
### Nested Schema for `schedules.spec`

Expand Down
157 changes: 92 additions & 65 deletions docs/resources/backup_schedule.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
data "tanzu-mission-control_backup_schedule" "demo" {
name = "BACKUP_SCHEDULE_NAME"
scope {
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
name = "TARGET_LOCATION_NAME"
cluster {
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
}
}

query = "QUERY"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
resource "tanzu-mission-control_backup_schedule" "sample-full" {
name = "full-weekly"
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
scope {
cluster {
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
}
}

scope = "FULL_CLUSTER"
backup_scope = "FULL_CLUSTER"

spec {
schedule {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
resource "tanzu-mission-control_backup_schedule" "sample-full" {
name = "label-based-no-storage"
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
scope {
cluster {
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
}
}

scope = "LABEL_SELECTOR"
backup_scope = "LABEL_SELECTOR"


spec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
resource "tanzu-mission-control_backup_schedule" "sample-full" {
name = "namespaces-hourly"
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"

scope = "SET_NAMESPACES"
scope {
cluster {
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
cluster_name = "CLS_NAME"
}
}

backup_scope = "SET_NAMESPACES"

spec {
schedule {
Expand Down
30 changes: 21 additions & 9 deletions internal/resources/cluster/backupschedule/converter_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ var (
)

var tfModelResourceMap = &tfModelConverterHelper.BlockToStruct{
NameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "name"),
ClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterName"),
ManagementClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "managementClusterName"),
ProvisionerNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "provisionerName"),
common.MetaKey: common.GetMetaConverterMap(tfModelConverterHelper.DefaultModelPathSeparator),
NameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "name"),
ScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterGroupScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterGroupNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterGroupName"),
},
ClusterScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterName"),
ManagementClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "managementClusterName"),
ProvisionerNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "provisionerName"),
},
},
common.MetaKey: common.GetMetaConverterMap(tfModelConverterHelper.DefaultModelPathSeparator),
SpecKey: &tfModelConverterHelper.BlockToStruct{
PausedKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "paused"),
ScheduleKey: &tfModelConverterHelper.BlockToStruct{
Expand Down Expand Up @@ -121,11 +128,16 @@ var tfModelDataSourceRequestMap = &tfModelConverterHelper.BlockToStruct{
SortByKey: "sortBy",
QueryKey: "query",
IncludeTotalCountKey: "includeTotal",
NameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "name"),
ScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("searchScope", "clusterName"),
ManagementClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("searchScope", "managementClusterName"),
ProvisionerNameKey: tfModelConverterHelper.BuildDefaultModelPath("searchScope", "provisionerName"),
NameKey: tfModelConverterHelper.BuildDefaultModelPath("searchScope", "name"),
ClusterGroupScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterGroupNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterGroupName"),
},
ClusterScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterName"),
ManagementClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "managementClusterName"),
ProvisionerNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "provisionerName"),
},
},
}

Expand Down
161 changes: 98 additions & 63 deletions internal/resources/cluster/backupschedule/datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,80 +16,115 @@ const (
IncludeTotalCountKey = "include_total_count"
SchedulesKey = "schedules"
TotalCountKey = "total_count"
ScopeKey = "scope"
ClusterScopeKey = "cluster"
ClusterGroupScopeKey = "cluster_group"
ClusterGroupNameKey = "cluster_group_name"
)

var backupScheduleDataSourceSchema = map[string]*schema.Schema{
ScopeKey: searchScopeSchema,
SortByKey: sortBySchema,
QueryKey: querySchema,
IncludeTotalCountKey: includeTotalSchema,
SchedulesKey: schedulesSchema,
TotalCountKey: totalCountSchema,
}
var (
nameDSSchema = &schema.Schema{
Type: schema.TypeString,
Description: "The name of the backup schedule",
Required: true,
ForceNew: true,
}

var searchScopeSchema = &schema.Schema{
Type: schema.TypeList,
Description: "Search scope block",
MaxItems: 1,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
ClusterNameKey: clusterNameSchema,
ManagementClusterNameKey: managementClusterNameDSSchema,
ProvisionerNameKey: provisionerNameDSSchema,
NameKey: nameDSSchema,
},
},
}
managementClusterNameDSSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Management cluster name",
Required: true,
ForceNew: true,
}

var nameDSSchema = &schema.Schema{
Type: schema.TypeString,
Description: "The name of the backup schedule",
Optional: true,
}
provisionerNameDSSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Cluster provisioner name",
Required: true,
ForceNew: true,
}

var managementClusterNameDSSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Management cluster name",
Optional: true,
}
sortBySchema = &schema.Schema{
Type: schema.TypeString,
Description: "Sort backups by field.",
Optional: true,
}

var provisionerNameDSSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Cluster provisioner name",
Optional: true,
}
querySchema = &schema.Schema{
Type: schema.TypeString,
Description: "Define a query for listing backups",
Optional: true,
}

var sortBySchema = &schema.Schema{
Type: schema.TypeString,
Description: "Sort backups by field.",
Optional: true,
}
includeTotalSchema = &schema.Schema{
Type: schema.TypeBool,
Description: "Whether to include total count of backups.\n(Default: True)",
Optional: true,
Default: true,
}

var querySchema = &schema.Schema{
Type: schema.TypeString,
Description: "Define a query for listing backups",
Optional: true,
}
schedulesSchema = &schema.Schema{
Type: schema.TypeList,
Description: "A list of schedules returned",
Computed: true,
Elem: &schema.Resource{
Schema: backupScheduleResourceSchema,
},
}

var includeTotalSchema = &schema.Schema{
Type: schema.TypeBool,
Description: "Whether to include total count of backups.\n(Default: True)",
Optional: true,
Default: true,
}
totalCountSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Total count of schedules returned",
Computed: true,
}

var schedulesSchema = &schema.Schema{
backupScheduleDataSourceSchema = map[string]*schema.Schema{
NameKey: nameDSSchema,
ScopeKey: searchScopeSchema,
SortByKey: sortBySchema,
QueryKey: querySchema,
IncludeTotalCountKey: includeTotalSchema,
SchedulesKey: schedulesSchema,
TotalCountKey: totalCountSchema,
}
)

var searchScopeSchema = &schema.Schema{
Type: schema.TypeList,
Description: "A list of schedules returned",
Computed: true,
Description: "Search scope block",
MaxItems: 1,
Required: true,
Elem: &schema.Resource{
Schema: backupScheduleResourceSchema,
Schema: map[string]*schema.Schema{
ClusterGroupScopeKey: {
Type: schema.TypeList,
Optional: true,
Description: "Cluster group scope block",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
ClusterGroupNameKey: {
Type: schema.TypeString,
Description: "Cluster group name",
Required: true,
ForceNew: true,
},
},
},
},
ClusterScopeKey: {
Type: schema.TypeList,
Optional: true,
Description: "Cluster scope block",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
ClusterNameKey: clusterNameSchema,
ManagementClusterNameKey: managementClusterNameDSSchema,
ProvisionerNameKey: provisionerNameDSSchema,
},
},
},
},
},
}

var totalCountSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Total count of schedules returned",
Computed: true,
}
Loading

0 comments on commit 4d323d0

Please sign in to comment.