Skip to content

Commit 635d7d4

Browse files
shobha2626tenthirtyam
authored andcommitted
Schema changes
1 parent cbeaf06 commit 635d7d4

15 files changed

+198
-17
lines changed

internal/client/cluster/dataprotection/dataprotection_resource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport"
1313
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
14-
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/dataprotection"
14+
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
1515
)
1616

1717
const (

internal/provider/provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ package provider
77

88
import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
dataprotection2 "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
1011

1112
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
1213
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/akscluster"
1314
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
1415
"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"
1616
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/integration"
1717
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/nodepools"
1818
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/clustergroup"
@@ -78,7 +78,7 @@ func Provider() *schema.Provider {
7878
helmrelease.ResourceName: helmrelease.ResourceHelmRelease(),
7979
helmfeature.ResourceName: helmfeature.ResourceHelm(),
8080
backupschedule.ResourceName: backupschedule.ResourceBackupSchedule(),
81-
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
81+
dataprotection2.ResourceName: dataprotection2.ResourceEnableDataProtection(),
8282
targetlocation.ResourceName: targetlocation.ResourceTargetLocation(),
8383
},
8484
DataSourcesMap: map[string]*schema.Resource{

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SPDX-License-Identifier: MPL-2.0
99
package backupscheduletests
1010

1111
import (
12+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
1213
"testing"
1314

1415
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -17,7 +18,6 @@ import (
1718
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
1819
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
1920
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"
2121
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
2222
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
2323
)
@@ -36,7 +36,7 @@ func initTestProvider(t *testing.T) *schema.Provider {
3636
ResourcesMap: map[string]*schema.Resource{
3737
cluster.ResourceName: cluster.ResourceTMCCluster(),
3838
targetlocationres.ResourceName: targetlocationres.ResourceTargetLocation(),
39-
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
39+
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
4040
backupscheduleres.ResourceName: backupscheduleres.ResourceBackupSchedule(),
4141
},
4242
DataSourcesMap: map[string]*schema.Resource{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ package backupscheduletests
77

88
import (
99
"fmt"
10+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/tests"
1011
"strings"
1112

1213
clusterres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
1314
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"
1515
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
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"

internal/resources/cluster/dataprotection/converter_mapping.go internal/resources/dataprotection/converter_mapping.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package dataprotection
77

88
import (
99
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"
10+
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
1111
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
1212
)
1313

internal/resources/cluster/dataprotection/resource_enable_data_protection.go internal/resources/dataprotection/resource_enable_data_protection.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ package dataprotection
77

88
import (
99
"context"
10+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
11+
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
12+
dataprotectionscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/scope"
1013
"strings"
1114
"time"
1215

@@ -17,7 +20,7 @@ import (
1720
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
1821
clienterrors "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/errors"
1922
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
20-
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/dataprotection"
23+
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
2124
)
2225

2326
func ResourceEnableDataProtection() *schema.Resource {
@@ -35,10 +38,28 @@ func ResourceEnableDataProtection() *schema.Resource {
3538

3639
func resourceEnableDataProtectionCreate(ctx context.Context, data *schema.ResourceData, m interface{}) (diags diag.Diagnostics) {
3740
config := m.(authctx.TanzuContext)
38-
model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{})
41+
/*model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{})
3942
4043
if err != nil {
4144
return diag.FromErr(errors.Wrapf(err, "Couldn't create Tanzu Mission Control data protection configurations."))
45+
}*/
46+
47+
scopedFullNameData := dataprotectionscope.ConstructScope(data)
48+
49+
if scopedFullNameData == nil {
50+
return diag.Errorf("Unable to enable Tanzu Mission Control Data Protection; Scope full name is empty")
51+
}
52+
53+
var (
54+
UID string
55+
meta = common.ConstructMeta(data)
56+
)
57+
58+
switch scopedFullNameData.Scope {
59+
case commonscope.ClusterScope:
60+
if scopedFullNameData.FullnameCluster != nil {
61+
specVal, err :=
62+
}
4263
}
4364

4465
request := &dataprotectionmodels.VmwareTanzuManageV1alpha1ClusterDataprotectionCreateDataProtectionRequest{

internal/resources/cluster/dataprotection/schema.go internal/resources/dataprotection/schema.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ package dataprotection
77

88
import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
1110
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
11+
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
12+
dataprotectionscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/scope"
1213
)
1314

1415
const (
@@ -37,6 +38,7 @@ var enableDataProtectionSchema = map[string]*schema.Schema{
3738
SpecKey: specSchema,
3839
common.MetaKey: common.Meta,
3940
DeletionPolicyKey: deletionPolicySchema,
41+
commonscope.ScopeKey: dataprotectionscope.ScopeSchema,
4042
}
4143

4244
var clusterNameSchema = &schema.Schema{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright © 2023 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package dataprotectionscope
7+
8+
import (
9+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
10+
dataprotectionclustermodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
11+
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
12+
)
13+
14+
func ConstructDataProtectionClusterFullname(data []interface{}) (fullname *dataprotectionclustermodels.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName) {
15+
if len(data) == 0 || data[0] == nil {
16+
return fullname
17+
}
18+
19+
fullNameData, _ := data[0].(map[string]interface{})
20+
21+
fullname = &dataprotectionclustermodels.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName{}
22+
23+
if managementClusterNameValue, ok := fullNameData[commonscope.ManagementClusterNameKey]; ok {
24+
helper.SetPrimitiveValue(managementClusterNameValue, &fullname.ManagementClusterName, commonscope.ManagementClusterNameKey)
25+
}
26+
27+
if provisionerNameValue, ok := fullNameData[commonscope.ProvisionerNameKey]; ok {
28+
helper.SetPrimitiveValue(provisionerNameValue, &fullname.ProvisionerName, commonscope.ProvisionerNameKey)
29+
}
30+
31+
if nameValue, ok := fullNameData[commonscope.NameKey]; ok {
32+
helper.SetPrimitiveValue(nameValue, &fullname.ClusterName, commonscope.NameKey)
33+
}
34+
35+
return fullname
36+
}
37+
38+
func FlattenDataProtectionClusterFullname(fullname *dataprotectionclustermodels.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName) (data []interface{}) {
39+
if fullname == nil {
40+
return data
41+
}
42+
43+
flattenFullname := make(map[string]interface{})
44+
45+
flattenFullname[commonscope.ManagementClusterNameKey] = fullname.ManagementClusterName
46+
flattenFullname[commonscope.ProvisionerNameKey] = fullname.ProvisionerName
47+
flattenFullname[commonscope.NameKey] = fullname.ClusterName
48+
49+
return []interface{}{flattenFullname}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright © 2023 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package dataprotectionscope
7+
8+
import (
9+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
10+
dataprotectionclustergroupmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/clustergroup/dataprotection"
11+
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
12+
)
13+
14+
func ConstructDataProtectionClusterGroupFullname(data []interface{}) (fullname *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) {
15+
if len(data) == 0 || data[0] == nil {
16+
return fullname
17+
}
18+
19+
fullNameData, _ := data[0].(map[string]interface{})
20+
21+
fullname = &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName{}
22+
23+
if nameValue, ok := fullNameData[commonscope.NameKey]; ok {
24+
helper.SetPrimitiveValue(nameValue, &fullname.ClusterGroupName, commonscope.NameKey)
25+
}
26+
27+
return fullname
28+
}
29+
30+
func FlattenDataProtectionClusterGroupFullname(fullname *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (data []interface{}) {
31+
if fullname == nil {
32+
return data
33+
}
34+
35+
flattenFullname := make(map[string]interface{})
36+
37+
flattenFullname[commonscope.NameKey] = fullname.ClusterGroupName
38+
39+
return []interface{}{flattenFullname}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright © 2023 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package dataprotectionscope
7+
8+
import (
9+
"fmt"
10+
"golang.org/x/exp/slices"
11+
"strings"
12+
13+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14+
15+
dataprotectionclustermodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
16+
dataprotectionclustergroupmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/clustergroup/dataprotection"
17+
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
18+
)
19+
20+
// ScopedFullname is a struct for all types of helm release full names.
21+
type ScopedFullname struct {
22+
Scope commonscope.Scope
23+
FullnameCluster *dataprotectionclustermodel.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName
24+
FullnameClusterGroup *dataprotectionclustergroupmodel.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName
25+
}
26+
27+
var (
28+
ScopesAllowed = [...]string{commonscope.ClusterKey, commonscope.ClusterGroupKey}
29+
ScopeSchema = commonscope.GetScopeSchema(
30+
commonscope.WithDescription(fmt.Sprintf("Scope for the Data Protection, having one of the valid scopes: %v.", strings.Join(ScopesAllowed[:], `, `))),
31+
commonscope.WithScopes(ScopesAllowed[:]))
32+
)
33+
34+
func ConstructScope(d *schema.ResourceData) (scopedFullnameData *ScopedFullname) {
35+
value, ok := d.GetOk(commonscope.ScopeKey)
36+
37+
if !ok {
38+
return scopedFullnameData
39+
}
40+
41+
data, _ := value.([]interface{})
42+
43+
if len(data) == 0 || data[0] == nil {
44+
return scopedFullnameData
45+
}
46+
47+
scopeData := data[0].(map[string]interface{})
48+
49+
if clusterData, ok := scopeData[commonscope.ClusterKey]; ok && slices.Contains(ScopesAllowed[:], commonscope.ClusterKey) {
50+
if clusterValue, ok := clusterData.([]interface{}); ok && len(clusterValue) != 0 {
51+
scopedFullnameData = &ScopedFullname{
52+
Scope: commonscope.ClusterScope,
53+
FullnameCluster: ConstructDataProtectionClusterFullname(clusterValue),
54+
}
55+
}
56+
}
57+
58+
if clusterGroupData, ok := scopeData[commonscope.ClusterGroupKey]; ok && slices.Contains(ScopesAllowed[:], commonscope.ClusterGroupKey) {
59+
if clusterGroupValue, ok := clusterGroupData.([]interface{}); ok && len(clusterGroupValue) != 0 {
60+
scopedFullnameData = &ScopedFullname{
61+
Scope: commonscope.ClusterGroupScope,
62+
FullnameClusterGroup: ConstructDataProtectionClusterGroupFullname(clusterGroupValue),
63+
}
64+
}
65+
}
66+
67+
return scopedFullnameData
68+
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ SPDX-License-Identifier: MPL-2.0
99
package dataprotectiontests
1010

1111
import (
12+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
1213
"testing"
1314

1415
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1516
"github.com/stretchr/testify/require"
1617

1718
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
1819
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
19-
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
2020
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
2121
)
2222

@@ -28,8 +28,8 @@ func initTestProvider(t *testing.T) *schema.Provider {
2828
testAccProvider := &schema.Provider{
2929
Schema: authctx.ProviderAuthSchema(),
3030
ResourcesMap: map[string]*schema.Resource{
31-
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
32-
cluster.ResourceName: cluster.ResourceTMCCluster(),
31+
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
32+
cluster.ResourceName: cluster.ResourceTMCCluster(),
3333
},
3434
ConfigureContextFunc: authctx.ProviderConfigureContext,
3535
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ package dataprotectiontests
77

88
import (
99
"fmt"
10+
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
1011
"strings"
1112

1213
clusterres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
13-
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
1414
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
1515
)
1616

internal/resources/targetlocation/tests/datasource_tf_configs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ package targetlocationtests
77

88
import (
99
"fmt"
10+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/tests"
1011

11-
dataprotectiontests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection/tests"
1212
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
1313
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
1414
)

internal/resources/targetlocation/tests/helper_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ SPDX-License-Identifier: MPL-2.0
99
package targetlocationtests
1010

1111
import (
12+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
1213
"testing"
1314

1415
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1516
"github.com/stretchr/testify/require"
1617

1718
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
1819
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
19-
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
2020
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/clustergroup"
2121
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
2222
credentialres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/credential"
@@ -37,7 +37,7 @@ func initTestProvider(t *testing.T) *schema.Provider {
3737
Schema: authctx.ProviderAuthSchema(),
3838
ResourcesMap: map[string]*schema.Resource{
3939
targetlocationres.ResourceName: targetlocationres.ResourceTargetLocation(),
40-
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
40+
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
4141
cluster.ResourceName: cluster.ResourceTMCCluster(),
4242
clustergroup.ResourceName: clustergroup.ResourceClusterGroup(),
4343
credentialres.ResourceName: credentialres.ResourceCredential(),

0 commit comments

Comments
 (0)