Skip to content

Commit dd01311

Browse files
rnarenpujarieastaga
authored andcommitted
Update data protection resource to support cluster group scope
Signed-off-by: rnarenpujari <rnarenpujari@gmail.com>
1 parent 2f73976 commit dd01311

File tree

14 files changed

+692
-305
lines changed

14 files changed

+692
-305
lines changed

internal/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/akscluster"
1313
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
1414
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
15-
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
1615
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/integration"
1716
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/nodepools"
1817
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/clusterclass"
1918
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/clustergroup"
2019
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/credential"
2120
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/customiamrole"
2221
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/custompolicytemplate"
22+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
2323
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/ekscluster"
2424
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/gitrepository"
2525
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/helmcharts"

internal/resources/cluster/backupschedule/tests/helper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
1818
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
1919
backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
20-
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
2120
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
21+
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
2222
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
2323
)
2424

internal/resources/cluster/backupschedule/tests/resource_tf_configs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
clusterres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
1313
backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
14-
dataprotectiontests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection/tests"
1514
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
15+
dataprotectiontests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/tests"
1616
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
1717
targetlocationtests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation/tests"
1818
)

internal/resources/cluster/dataprotection/converter_mapping.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

internal/resources/cluster/dataprotection/resource_enable_data_protection.go

Lines changed: 0 additions & 250 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Copyright © 2023 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package dataprotection
7+
8+
import (
9+
tfModelConverterHelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper/converter"
10+
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/dataprotection"
11+
dataprotectioncgmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/clustergroup/dataprotection"
12+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
13+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/scope"
14+
)
15+
16+
var (
17+
matchExpressionsArrayField = tfModelConverterHelper.BuildArrayField("matchExpressions")
18+
)
19+
20+
func getTFModelConverterCluster() tfModelConverterHelper.TFSchemaModelConverter[*dataprotectionmodels.VmwareTanzuManageV1alpha1ClusterDataprotectionDataProtection] {
21+
return tfModelConverterHelper.TFSchemaModelConverter[*dataprotectionmodels.VmwareTanzuManageV1alpha1ClusterDataprotectionDataProtection]{
22+
TFModelMap: getTFModelMapCommon(false),
23+
}
24+
}
25+
26+
func getTFModelConverterClusterGroup() tfModelConverterHelper.TFSchemaModelConverter[*dataprotectioncgmodels.VmwareTanzuManageV1alpha1ClustergroupDataprotectionDataProtection] {
27+
return tfModelConverterHelper.TFSchemaModelConverter[*dataprotectioncgmodels.VmwareTanzuManageV1alpha1ClustergroupDataprotectionDataProtection]{
28+
TFModelMap: getTFModelMapCommon(true),
29+
}
30+
}
31+
32+
func getTFModelMapCommon(forClusterGroup bool) *tfModelConverterHelper.BlockToStruct {
33+
var specBlock *tfModelConverterHelper.BlockToStruct
34+
if forClusterGroup {
35+
specBlock = &tfModelConverterHelper.BlockToStruct{
36+
DisableResticKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "atomicSpec", "disableRestic"),
37+
EnableCSISnapshotsKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "atomicSpec", "enableCsiSnapshots"),
38+
EnableAllAPIGroupVersionsBackupKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "atomicSpec", "enableAllApiGroupVersionsBackup"),
39+
SelectorKey: &tfModelConverterHelper.BlockToStruct{
40+
NamesKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "selector", "names"),
41+
ExcludedNamesKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "selector", "excludedNames"),
42+
LabelSelectorKey: &tfModelConverterHelper.BlockToStruct{
43+
MatchExpressionsKey: &tfModelConverterHelper.BlockSliceToStructSlice{
44+
{
45+
KeyKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "selector", "labelSelector", matchExpressionsArrayField, "key"),
46+
OperatorKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "selector", "labelSelector", matchExpressionsArrayField, "operator"),
47+
ValuesKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "selector", "labelSelector", matchExpressionsArrayField, "values"),
48+
},
49+
},
50+
},
51+
},
52+
}
53+
} else {
54+
specBlock = &tfModelConverterHelper.BlockToStruct{
55+
DisableResticKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "disableRestic"),
56+
EnableCSISnapshotsKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "enableCsiSnapshots"),
57+
EnableAllAPIGroupVersionsBackupKey: tfModelConverterHelper.BuildDefaultModelPath("spec", "enableAllApiGroupVersionsBackup"),
58+
}
59+
}
60+
61+
return &tfModelConverterHelper.BlockToStruct{
62+
scope.ScopeKey: &tfModelConverterHelper.BlockToStruct{
63+
scope.ClusterKey: &tfModelConverterHelper.BlockToStruct{
64+
scope.ClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterName"),
65+
scope.ManagementClusterNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "managementClusterName"),
66+
scope.ProvisionerNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "provisionerName"),
67+
},
68+
scope.ClusterGroupKey: &tfModelConverterHelper.BlockToStruct{
69+
scope.ClusterGroupNameKey: tfModelConverterHelper.BuildDefaultModelPath("fullName", "clusterGroupName"),
70+
},
71+
},
72+
common.MetaKey: common.GetMetaConverterMap(tfModelConverterHelper.DefaultModelPathSeparator),
73+
SpecKey: specBlock,
74+
}
75+
}

0 commit comments

Comments
 (0)