Skip to content

Commit

Permalink
Merge pull request #339 from vmware/mshobha/scope-data-protection
Browse files Browse the repository at this point in the history
Add scope block support to Data Protection
  • Loading branch information
shobha2626 authored Nov 17, 2023
2 parents 2212862 + 424816f commit b0655a2
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 40 deletions.
32 changes: 26 additions & 6 deletions docs/resources/enable_data_protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ For more information regarding data protection, see [Data Protection][data-prote

```terraform
resource "tanzu-mission-control_enable_data_protection" "demo" {
cluster_name = "CLS_NAME"
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
scope {
cluster {
cluster_name = "CLS_NAME"
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
}
}
spec {
disable_restic = false
Expand All @@ -38,9 +42,7 @@ resource "tanzu-mission-control_enable_data_protection" "demo" {

### Required

- `cluster_name` (String) Cluster name
- `management_cluster_name` (String) Management cluster name
- `provisioner_name` (String) Cluster provisioner name
- `scope` (Block List, Min: 1, Max: 1) Scope block for Data Protection (cluster) (see [below for nested schema](#nestedblock--scope))

### Optional

Expand All @@ -52,6 +54,24 @@ resource "tanzu-mission-control_enable_data_protection" "demo" {

- `id` (String) The ID of this resource.

<a id="nestedblock--scope"></a>
### Nested Schema for `scope`

Optional:

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

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

Required:

- `cluster_name` (String) Cluster name
- `management_cluster_name` (String) Management cluster name
- `provisioner_name` (String) Cluster provisioner name



<a id="nestedblock--deletion_policy"></a>
### Nested Schema for `deletion_policy`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
resource "tanzu-mission-control_enable_data_protection" "demo" {
cluster_name = "CLS_NAME"
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
scope {
cluster {
cluster_name = "CLS_NAME"
management_cluster_name = "MGMT_CLS_NAME"
provisioner_name = "PROVISIONER_NAME"
}
}

spec {
disable_restic = false
Expand Down
15 changes: 11 additions & 4 deletions internal/resources/cluster/dataprotection/converter_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ import (
)

var tfModelMap = &tfModelConverterHelper.BlockToStruct{
ClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterName"),
ManagementClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "managementClusterName"),
ProvisionerNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "provisionerName"),
common.MetaKey: common.GetMetaConverterMap(tfModelConverterHelper.DefaultModelPathSeparator),
ScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterName"),
ManagementClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "managementClusterName"),
ProvisionerNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "provisionerName"),
},
ClusterGroupScopeKey: &tfModelConverterHelper.BlockToStruct{
ClusterGroupNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterGroupName"),
},
},
common.MetaKey: common.GetMetaConverterMap(tfModelConverterHelper.DefaultModelPathSeparator),
SpecKey: &tfModelConverterHelper.BlockToStruct{
DisableResticKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "disableRestic"),
EnableCSISnapshotsKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "enableCsiSnapshots"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func resourceEnableDataProtectionRead(ctx context.Context, data *schema.Resource
var resp *dataprotectionmodels.VmwareTanzuManageV1alpha1ClusterDataprotectionListDataProtectionsResponse

config := m.(authctx.TanzuContext)
model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{ClusterNameKey, ProvisionerNameKey, ManagementClusterNameKey})
model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{ScopeKey, ClusterScopeKey, ClusterNameKey, ProvisionerNameKey, ManagementClusterNameKey})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't read Tanzu Mission Control data protection configurations."))
Expand Down Expand Up @@ -124,7 +124,7 @@ func resourceEnableDataProtectionRead(ctx context.Context, data *schema.Resource

func resourceEnableDataProtectionDelete(ctx context.Context, data *schema.ResourceData, m interface{}) (diags diag.Diagnostics) {
config := m.(authctx.TanzuContext)
model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{ClusterNameKey, ProvisionerNameKey, ManagementClusterNameKey})
model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{ScopeKey, ClusterScopeKey, ClusterNameKey, ProvisionerNameKey, ManagementClusterNameKey})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't delete Tanzu Mission Control data protection configurations."))
Expand Down
87 changes: 62 additions & 25 deletions internal/resources/cluster/dataprotection/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import (
)

const (
ResourceName = "tanzu-mission-control_enable_data_protection"
ResourceName = "tanzu-mission-control_enable_data_protection"
ScopeKey = "scope"
ClusterScopeKey = "cluster"
ClusterGroupScopeKey = "cluster_group"

// Root Keys.
ClusterNameKey = "cluster_name"
ClusterGroupNameKey = "cluster_group_name"
ManagementClusterNameKey = "management_cluster_name"
ProvisionerNameKey = "provisioner_name"
SpecKey = "spec"
Expand All @@ -31,33 +35,66 @@ const (
)

var enableDataProtectionSchema = map[string]*schema.Schema{
ClusterNameKey: clusterNameSchema,
ManagementClusterNameKey: managementClusterNameSchema,
ProvisionerNameKey: provisionerNameSchema,
SpecKey: specSchema,
common.MetaKey: common.Meta,
DeletionPolicyKey: deletionPolicySchema,
ScopeKey: scopeSchema,
SpecKey: specSchema,
common.MetaKey: common.Meta,
DeletionPolicyKey: deletionPolicySchema,
}

var clusterNameSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Cluster name",
Required: true,
ForceNew: true,
}

var managementClusterNameSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Management cluster name",
Required: true,
ForceNew: true,
}

var provisionerNameSchema = &schema.Schema{
Type: schema.TypeString,
Description: "Cluster provisioner name",
var scopeSchema = &schema.Schema{
Type: schema.TypeList,
Description: "Scope block for Data Protection (cluster/cluster group)",
Required: true,
ForceNew: true,
MaxItems: 1,
Optional: false,
Elem: &schema.Resource{
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: {
Type: schema.TypeString,
Description: "Cluster name",
Required: true,
ForceNew: true,
},
ManagementClusterNameKey: {
Type: schema.TypeString,
Description: "Management cluster name",
Required: true,
ForceNew: true,
},
ProvisionerNameKey: {
Type: schema.TypeString,
Description: "Cluster provisioner name",
Required: true,
ForceNew: true,
},
},
},
},
},
},
}

var specSchema = &schema.Schema{
Expand Down

0 comments on commit b0655a2

Please sign in to comment.