-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f75b8f2
commit 39fe4de
Showing
15 changed files
with
198 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
"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 | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters