Skip to content

Commit

Permalink
Schema changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shobha2626 committed Nov 16, 2023
1 parent f75b8f2 commit 39fe4de
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/dataprotection"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package provider

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

Check failure on line 10 in internal/provider/provider.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection (-: # github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/akscluster"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/integration"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/nodepools"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/clustergroup"
Expand Down Expand Up @@ -78,7 +78,7 @@ func Provider() *schema.Provider {
helmrelease.ResourceName: helmrelease.ResourceHelmRelease(),
helmfeature.ResourceName: helmfeature.ResourceHelm(),
backupschedule.ResourceName: backupschedule.ResourceBackupSchedule(),
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
dataprotection2.ResourceName: dataprotection2.ResourceEnableDataProtection(),
targetlocation.ResourceName: targetlocation.ResourceTargetLocation(),
},
DataSourcesMap: map[string]*schema.Resource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SPDX-License-Identifier: MPL-2.0
package backupscheduletests

import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
)
Expand All @@ -36,7 +36,7 @@ func initTestProvider(t *testing.T) *schema.Provider {
ResourcesMap: map[string]*schema.Resource{
cluster.ResourceName: cluster.ResourceTMCCluster(),
targetlocationres.ResourceName: targetlocationres.ResourceTargetLocation(),
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
backupscheduleres.ResourceName: backupscheduleres.ResourceBackupSchedule(),
},
DataSourcesMap: map[string]*schema.Resource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ package backupscheduletests

import (
"fmt"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/tests"
"strings"

clusterres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule"
dataprotectiontests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection/tests"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
targetlocationtests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation/tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package dataprotection

import (
tfModelConverterHelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper/converter"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/dataprotection"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package dataprotection

import (
"context"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
dataprotectionscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/scope"
"strings"
"time"

Expand All @@ -17,7 +20,7 @@ import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
clienterrors "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/errors"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/dataprotection"
dataprotectionmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
)

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

func resourceEnableDataProtectionCreate(ctx context.Context, data *schema.ResourceData, m interface{}) (diags diag.Diagnostics) {
config := m.(authctx.TanzuContext)
model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{})
/*model, err := tfModelConverter.ConvertTFSchemaToAPIModel(data, []string{})
if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't create Tanzu Mission Control data protection configurations."))
}*/

scopedFullNameData := dataprotectionscope.ConstructScope(data)

if scopedFullNameData == nil {
return diag.Errorf("Unable to enable Tanzu Mission Control Data Protection; Scope full name is empty")
}

var (
UID string
meta = common.ConstructMeta(data)
)

switch scopedFullNameData.Scope {
case commonscope.ClusterScope:
if scopedFullNameData.FullnameCluster != nil {
specVal, err :=
}

Check failure on line 62 in internal/resources/dataprotection/resource_enable_data_protection.go

View workflow job for this annotation

GitHub Actions / Test and coverage

syntax error: unexpected }, expecting expression

Check failure on line 62 in internal/resources/dataprotection/resource_enable_data_protection.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected }, expecting expression (typecheck)

Check failure on line 62 in internal/resources/dataprotection/resource_enable_data_protection.go

View workflow job for this annotation

GitHub Actions / lint

expected operand, found '}' (typecheck)

Check failure on line 62 in internal/resources/dataprotection/resource_enable_data_protection.go

View workflow job for this annotation

GitHub Actions / lint

expected operand, found '}' (typecheck)

Check failure on line 62 in internal/resources/dataprotection/resource_enable_data_protection.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected }, expecting expression) (typecheck)

Check failure on line 62 in internal/resources/dataprotection/resource_enable_data_protection.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected }, expecting expression) (typecheck)

Check failure on line 62 in internal/resources/dataprotection/resource_enable_data_protection.go

View workflow job for this annotation

GitHub Actions / Test and coverage

syntax error: unexpected }, expecting expression
}

request := &dataprotectionmodels.VmwareTanzuManageV1alpha1ClusterDataprotectionCreateDataProtectionRequest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package dataprotection

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
dataprotectionscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/scope"
)

const (
Expand Down Expand Up @@ -37,6 +38,7 @@ var enableDataProtectionSchema = map[string]*schema.Schema{
SpecKey: specSchema,
common.MetaKey: common.Meta,
DeletionPolicyKey: deletionPolicySchema,
commonscope.ScopeKey: dataprotectionscope.ScopeSchema,
}

var clusterNameSchema = &schema.Schema{
Expand Down
50 changes: 50 additions & 0 deletions internal/resources/dataprotection/scope/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionscope

import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
dataprotectionclustermodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
)

func ConstructDataProtectionClusterFullname(data []interface{}) (fullname *dataprotectionclustermodels.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName) {
if len(data) == 0 || data[0] == nil {
return fullname
}

fullNameData, _ := data[0].(map[string]interface{})

fullname = &dataprotectionclustermodels.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName{}

if managementClusterNameValue, ok := fullNameData[commonscope.ManagementClusterNameKey]; ok {
helper.SetPrimitiveValue(managementClusterNameValue, &fullname.ManagementClusterName, commonscope.ManagementClusterNameKey)
}

if provisionerNameValue, ok := fullNameData[commonscope.ProvisionerNameKey]; ok {
helper.SetPrimitiveValue(provisionerNameValue, &fullname.ProvisionerName, commonscope.ProvisionerNameKey)
}

if nameValue, ok := fullNameData[commonscope.NameKey]; ok {
helper.SetPrimitiveValue(nameValue, &fullname.ClusterName, commonscope.NameKey)
}

return fullname
}

func FlattenDataProtectionClusterFullname(fullname *dataprotectionclustermodels.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName) (data []interface{}) {
if fullname == nil {
return data
}

flattenFullname := make(map[string]interface{})

flattenFullname[commonscope.ManagementClusterNameKey] = fullname.ManagementClusterName
flattenFullname[commonscope.ProvisionerNameKey] = fullname.ProvisionerName
flattenFullname[commonscope.NameKey] = fullname.ClusterName

return []interface{}{flattenFullname}
}
40 changes: 40 additions & 0 deletions internal/resources/dataprotection/scope/cluster_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionscope

import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
dataprotectionclustergroupmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/clustergroup/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
)

func ConstructDataProtectionClusterGroupFullname(data []interface{}) (fullname *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) {
if len(data) == 0 || data[0] == nil {
return fullname
}

fullNameData, _ := data[0].(map[string]interface{})

fullname = &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName{}

if nameValue, ok := fullNameData[commonscope.NameKey]; ok {
helper.SetPrimitiveValue(nameValue, &fullname.ClusterGroupName, commonscope.NameKey)
}

return fullname
}

func FlattenDataProtectionClusterGroupFullname(fullname *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (data []interface{}) {
if fullname == nil {
return data
}

flattenFullname := make(map[string]interface{})

flattenFullname[commonscope.NameKey] = fullname.ClusterGroupName

return []interface{}{flattenFullname}
}
68 changes: 68 additions & 0 deletions internal/resources/dataprotection/scope/scope.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0
*/

package dataprotectionscope

import (
"fmt"
"golang.org/x/exp/slices"

Check failure on line 10 in internal/resources/dataprotection/scope/scope.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/vmware/terraform-provider-tanzu-mission-control (goimports)
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

dataprotectionclustermodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/dataprotection"
dataprotectionclustergroupmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/clustergroup/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
)

// ScopedFullname is a struct for all types of helm release full names.
type ScopedFullname struct {
Scope commonscope.Scope
FullnameCluster *dataprotectionclustermodel.VmwareTanzuManageV1alpha1ClusterDataprotectionFullName
FullnameClusterGroup *dataprotectionclustergroupmodel.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName
}

var (
ScopesAllowed = [...]string{commonscope.ClusterKey, commonscope.ClusterGroupKey}
ScopeSchema = commonscope.GetScopeSchema(
commonscope.WithDescription(fmt.Sprintf("Scope for the Data Protection, having one of the valid scopes: %v.", strings.Join(ScopesAllowed[:], `, `))),
commonscope.WithScopes(ScopesAllowed[:]))
)

func ConstructScope(d *schema.ResourceData) (scopedFullnameData *ScopedFullname) {
value, ok := d.GetOk(commonscope.ScopeKey)

if !ok {
return scopedFullnameData
}

data, _ := value.([]interface{})

if len(data) == 0 || data[0] == nil {
return scopedFullnameData
}

scopeData := data[0].(map[string]interface{})

if clusterData, ok := scopeData[commonscope.ClusterKey]; ok && slices.Contains(ScopesAllowed[:], commonscope.ClusterKey) {
if clusterValue, ok := clusterData.([]interface{}); ok && len(clusterValue) != 0 {
scopedFullnameData = &ScopedFullname{
Scope: commonscope.ClusterScope,
FullnameCluster: ConstructDataProtectionClusterFullname(clusterValue),
}
}
}

if clusterGroupData, ok := scopeData[commonscope.ClusterGroupKey]; ok && slices.Contains(ScopesAllowed[:], commonscope.ClusterGroupKey) {
if clusterGroupValue, ok := clusterGroupData.([]interface{}); ok && len(clusterGroupValue) != 0 {
scopedFullnameData = &ScopedFullname{
Scope: commonscope.ClusterGroupScope,
FullnameClusterGroup: ConstructDataProtectionClusterGroupFullname(clusterGroupValue),
}
}
}

return scopedFullnameData
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ SPDX-License-Identifier: MPL-2.0
package dataprotectiontests

import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
"testing"

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

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
)

Expand All @@ -28,8 +28,8 @@ func initTestProvider(t *testing.T) *schema.Provider {
testAccProvider := &schema.Provider{
Schema: authctx.ProviderAuthSchema(),
ResourcesMap: map[string]*schema.Resource{
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
cluster.ResourceName: cluster.ResourceTMCCluster(),
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
cluster.ResourceName: cluster.ResourceTMCCluster(),
},
ConfigureContextFunc: authctx.ProviderConfigureContext,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ package dataprotectiontests

import (
"fmt"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"

Check failure on line 10 in internal/resources/dataprotection/tests/resource_tf_configs.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection (-: # github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection
"strings"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package targetlocationtests

import (
"fmt"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection/tests"

dataprotectiontests "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection/tests"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
targetlocationres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/targetlocation"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/targetlocation/tests/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ SPDX-License-Identifier: MPL-2.0
package targetlocationtests

import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/dataprotection"
"testing"

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

"github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster"
dataprotectionres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/dataprotection"
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/clustergroup"
commonscope "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common/scope"
credentialres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/credential"
Expand All @@ -37,7 +37,7 @@ func initTestProvider(t *testing.T) *schema.Provider {
Schema: authctx.ProviderAuthSchema(),
ResourcesMap: map[string]*schema.Resource{
targetlocationres.ResourceName: targetlocationres.ResourceTargetLocation(),
dataprotectionres.ResourceName: dataprotectionres.ResourceEnableDataProtection(),
dataprotection.ResourceName: dataprotection.ResourceEnableDataProtection(),
cluster.ResourceName: cluster.ResourceTMCCluster(),
clustergroup.ResourceName: clustergroup.ResourceClusterGroup(),
credentialres.ResourceName: credentialres.ResourceCredential(),
Expand Down

0 comments on commit 39fe4de

Please sign in to comment.