From 4fc747871154cea8106b242ed10f39b8e8eba490 Mon Sep 17 00:00:00 2001 From: mshobha Date: Thu, 16 Nov 2023 12:04:55 +0530 Subject: [PATCH 1/2] Models and clients for DP cluster group Signed-off-by: mshobha --- .../backupschedule/backupschedule_resource.go | 2 +- .../dataprotection/dataprotection_resource.go | 106 +++++++++++++ .../cluster/backupschedule/backup_schedule.go | 0 .../cluster/backupschedule/error_mode.go | 0 .../cluster/backupschedule/exec.go | 0 .../cluster/backupschedule/fullname.go | 0 .../cluster/backupschedule/hooks.go | 0 .../cluster/backupschedule/label_selector.go | 0 .../list_backup_schedules_search_scope.go | 0 .../cluster/backupschedule/post_hook.go | 0 .../cluster/backupschedule/requests.go | 0 .../cluster/backupschedule/resource_hook.go | 0 .../cluster/backupschedule/schedule.go | 0 .../cluster/backupschedule/spec.go | 0 .../cluster/backupschedule/status.go | 0 .../cluster/backupschedule/status_phase.go | 0 .../cluster/backupschedule/template.go | 0 .../cluster/dataprotection/data_protection.go | 2 +- .../cluster/dataprotection/fullname.go | 2 +- .../cluster/dataprotection/requests.go | 2 +- .../cluster/dataprotection/spec.go | 2 +- .../cluster/dataprotection/status.go | 2 +- .../cluster/dataprotection/status_phase.go | 2 +- .../cluster/targetlocation/access_mode.go | 51 +++++++ .../cluster/targetlocation/assigned_groups.go | 47 ++++++ .../cluster/targetlocation/backup_location.go | 55 +++++++ .../cluster/targetlocation/config.go | 121 +++++++++++++++ .../cluster/targetlocation/fullname.go | 48 ++++++ .../list_backup_locations_search_scope.go | 48 ++++++ .../cluster/targetlocation/requests.go | 144 ++++++++++++++++++ .../cluster/targetlocation/spec.go | 61 ++++++++ .../cluster/targetlocation/status.go | 58 +++++++ .../cluster/targetlocation/status_phase.go | 75 +++++++++ .../cluster/targetlocation/status_type.go | 55 +++++++ .../cluster/targetlocation/target_provider.go | 55 +++++++ .../dataprotection/data_protection.go | 58 +++++++ .../clustergroup/dataprotection/fullname.go | 44 ++++++ .../dataprotection/label_selector.go | 53 +++++++ .../clustergroup/dataprotection/requests.go | 106 +++++++++++++ .../clustergroup/dataprotection/selector.go | 46 ++++++ .../clustergroup/dataprotection/spec.go | 60 ++++++++ .../clustergroup/dataprotection/status.go | 46 ++++++ .../dataprotection/status_details.go | 52 +++++++ .../dataprotection/status_phase.go | 75 +++++++++ .../backupschedule/converter_mapping.go | 2 +- .../datasource_backup_schedule.go | 2 +- .../resource_backup_schedule.go | 2 +- .../cluster/backupschedule/resource_schema.go | 2 +- .../tests/backup_schedule_test.go | 2 +- 49 files changed, 1476 insertions(+), 12 deletions(-) create mode 100644 internal/client/clustergroup/dataprotection/dataprotection_resource.go rename internal/models/{ => dataprotection}/cluster/backupschedule/backup_schedule.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/error_mode.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/exec.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/fullname.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/hooks.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/label_selector.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/list_backup_schedules_search_scope.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/post_hook.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/requests.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/resource_hook.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/schedule.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/spec.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/status.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/status_phase.go (100%) rename internal/models/{ => dataprotection}/cluster/backupschedule/template.go (100%) rename internal/models/{ => dataprotection}/cluster/dataprotection/data_protection.go (98%) rename internal/models/{ => dataprotection}/cluster/dataprotection/fullname.go (97%) rename internal/models/{ => dataprotection}/cluster/dataprotection/requests.go (98%) rename internal/models/{ => dataprotection}/cluster/dataprotection/spec.go (97%) rename internal/models/{ => dataprotection}/cluster/dataprotection/status.go (98%) rename internal/models/{ => dataprotection}/cluster/dataprotection/status_phase.go (99%) create mode 100644 internal/models/dataprotection/cluster/targetlocation/access_mode.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/assigned_groups.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/backup_location.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/config.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/fullname.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/list_backup_locations_search_scope.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/requests.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/spec.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/status.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/status_phase.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/status_type.go create mode 100644 internal/models/dataprotection/cluster/targetlocation/target_provider.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/data_protection.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/fullname.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/label_selector.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/requests.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/selector.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/spec.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/status.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/status_details.go create mode 100644 internal/models/dataprotection/clustergroup/dataprotection/status_phase.go diff --git a/internal/client/cluster/backupschedule/backupschedule_resource.go b/internal/client/cluster/backupschedule/backupschedule_resource.go index f80a88bb9..3b2a3d45b 100644 --- a/internal/client/cluster/backupschedule/backupschedule_resource.go +++ b/internal/client/cluster/backupschedule/backupschedule_resource.go @@ -12,7 +12,7 @@ import ( "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper" - backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule" + backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/backupschedule" ) const ( diff --git a/internal/client/clustergroup/dataprotection/dataprotection_resource.go b/internal/client/clustergroup/dataprotection/dataprotection_resource.go new file mode 100644 index 000000000..a71737463 --- /dev/null +++ b/internal/client/clustergroup/dataprotection/dataprotection_resource.go @@ -0,0 +1,106 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clustergroupdataprotectionclient + +import ( + "net/url" + + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport" + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper" + dataprotectionclustergroupmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/clustergroup/dataprotection" +) + +const ( + apiVersionAndGroup = "v1alpha1/clustergroups" + dataProtectionPath = "dataprotection" +) + +// New creates a new data protection resource service API client. +func New(transport *transport.Client) ClientService { + return &Client{Client: transport} +} + +/* +Client for data protection resource service API. +*/ +type Client struct { + *transport.Client +} + +// ClientService is the interface for Client methods. +type ClientService interface { + ClusterGroupDataProtectionResourceServiceCreate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) + + ClusterGroupDataProtectionResourceServiceDelete(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName, destroyBackups bool) error + + ClusterGroupDataProtectionResourceServiceList(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse, error) + + ClusterGroupDataProtectionResourceServiceUpdate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) +} + +/* +ClusterGroupDataProtectionResourceServiceCreate enables data protection on a cluster. +*/ +func (c *Client) ClusterGroupDataProtectionResourceServiceCreate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest, +) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) { + response := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse{} + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.DataProtection.FullName.ClusterGroupName, dataProtectionPath).String() + err := c.Create(requestURL, request, response) + + return response, err +} + +/* +ClusterGroupDataProtectionResourceServiceDelete disables data protection on a cluster group. +*/ +func (c *Client) ClusterGroupDataProtectionResourceServiceDelete(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName, deleteBackups bool) error { + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ClusterGroupName, dataProtectionPath) + queryParams := url.Values{} + + //queryParams.Add("fullName.clusterGroupName", fn.ClusterGroupName) + //queryParams.Add("delete_backups", strconv.FormatBool(deleteBackups)) + + requestURL = requestURL.AppendQueryParams(queryParams) + + return c.Delete(requestURL.String()) +} + +/* +ClusterGroupDataProtectionResourceServiceList gets data protection details. +*/ +func (c *Client) ClusterGroupDataProtectionResourceServiceList(fn *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse, error) { + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ClusterGroupName, dataProtectionPath) + queryParams := url.Values{} + + /*if fn.ManagementClusterName != "" { + queryParams.Add("searchScope.managementClusterName", fn.ManagementClusterName) + } + + if fn.ProvisionerName != "" { + queryParams.Add("searchScope.provisionerName", fn.ProvisionerName) + }*/ + + if len(queryParams) > 0 { + requestURL = requestURL.AppendQueryParams(queryParams) + } + + resp := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse{} + err := c.Get(requestURL.String(), resp) + + return resp, err +} + +/* +ClusterGroupDataProtectionResourceServiceUpdate updates a data protection configuration on a cluster. +*/ +func (c *Client) ClusterGroupDataProtectionResourceServiceUpdate(request *dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest, +) (*dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse, error) { + response := &dataprotectionclustergroupmodels.VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse{} + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.DataProtection.FullName.ClusterGroupName, dataProtectionPath).String() + err := c.Update(requestURL, request, response) + + return response, err +} diff --git a/internal/models/cluster/backupschedule/backup_schedule.go b/internal/models/dataprotection/cluster/backupschedule/backup_schedule.go similarity index 100% rename from internal/models/cluster/backupschedule/backup_schedule.go rename to internal/models/dataprotection/cluster/backupschedule/backup_schedule.go diff --git a/internal/models/cluster/backupschedule/error_mode.go b/internal/models/dataprotection/cluster/backupschedule/error_mode.go similarity index 100% rename from internal/models/cluster/backupschedule/error_mode.go rename to internal/models/dataprotection/cluster/backupschedule/error_mode.go diff --git a/internal/models/cluster/backupschedule/exec.go b/internal/models/dataprotection/cluster/backupschedule/exec.go similarity index 100% rename from internal/models/cluster/backupschedule/exec.go rename to internal/models/dataprotection/cluster/backupschedule/exec.go diff --git a/internal/models/cluster/backupschedule/fullname.go b/internal/models/dataprotection/cluster/backupschedule/fullname.go similarity index 100% rename from internal/models/cluster/backupschedule/fullname.go rename to internal/models/dataprotection/cluster/backupschedule/fullname.go diff --git a/internal/models/cluster/backupschedule/hooks.go b/internal/models/dataprotection/cluster/backupschedule/hooks.go similarity index 100% rename from internal/models/cluster/backupschedule/hooks.go rename to internal/models/dataprotection/cluster/backupschedule/hooks.go diff --git a/internal/models/cluster/backupschedule/label_selector.go b/internal/models/dataprotection/cluster/backupschedule/label_selector.go similarity index 100% rename from internal/models/cluster/backupschedule/label_selector.go rename to internal/models/dataprotection/cluster/backupschedule/label_selector.go diff --git a/internal/models/cluster/backupschedule/list_backup_schedules_search_scope.go b/internal/models/dataprotection/cluster/backupschedule/list_backup_schedules_search_scope.go similarity index 100% rename from internal/models/cluster/backupschedule/list_backup_schedules_search_scope.go rename to internal/models/dataprotection/cluster/backupschedule/list_backup_schedules_search_scope.go diff --git a/internal/models/cluster/backupschedule/post_hook.go b/internal/models/dataprotection/cluster/backupschedule/post_hook.go similarity index 100% rename from internal/models/cluster/backupschedule/post_hook.go rename to internal/models/dataprotection/cluster/backupschedule/post_hook.go diff --git a/internal/models/cluster/backupschedule/requests.go b/internal/models/dataprotection/cluster/backupschedule/requests.go similarity index 100% rename from internal/models/cluster/backupschedule/requests.go rename to internal/models/dataprotection/cluster/backupschedule/requests.go diff --git a/internal/models/cluster/backupschedule/resource_hook.go b/internal/models/dataprotection/cluster/backupschedule/resource_hook.go similarity index 100% rename from internal/models/cluster/backupschedule/resource_hook.go rename to internal/models/dataprotection/cluster/backupschedule/resource_hook.go diff --git a/internal/models/cluster/backupschedule/schedule.go b/internal/models/dataprotection/cluster/backupschedule/schedule.go similarity index 100% rename from internal/models/cluster/backupschedule/schedule.go rename to internal/models/dataprotection/cluster/backupschedule/schedule.go diff --git a/internal/models/cluster/backupschedule/spec.go b/internal/models/dataprotection/cluster/backupschedule/spec.go similarity index 100% rename from internal/models/cluster/backupschedule/spec.go rename to internal/models/dataprotection/cluster/backupschedule/spec.go diff --git a/internal/models/cluster/backupschedule/status.go b/internal/models/dataprotection/cluster/backupschedule/status.go similarity index 100% rename from internal/models/cluster/backupschedule/status.go rename to internal/models/dataprotection/cluster/backupschedule/status.go diff --git a/internal/models/cluster/backupschedule/status_phase.go b/internal/models/dataprotection/cluster/backupschedule/status_phase.go similarity index 100% rename from internal/models/cluster/backupschedule/status_phase.go rename to internal/models/dataprotection/cluster/backupschedule/status_phase.go diff --git a/internal/models/cluster/backupschedule/template.go b/internal/models/dataprotection/cluster/backupschedule/template.go similarity index 100% rename from internal/models/cluster/backupschedule/template.go rename to internal/models/dataprotection/cluster/backupschedule/template.go diff --git a/internal/models/cluster/dataprotection/data_protection.go b/internal/models/dataprotection/cluster/dataprotection/data_protection.go similarity index 98% rename from internal/models/cluster/dataprotection/data_protection.go rename to internal/models/dataprotection/cluster/dataprotection/data_protection.go index b9d02420e..7b404a1cf 100644 --- a/internal/models/cluster/dataprotection/data_protection.go +++ b/internal/models/dataprotection/cluster/dataprotection/data_protection.go @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MPL-2.0 */ -package dataprotectionmodels +package dataprotectionclustermodels import ( "github.com/go-openapi/swag" diff --git a/internal/models/cluster/dataprotection/fullname.go b/internal/models/dataprotection/cluster/dataprotection/fullname.go similarity index 97% rename from internal/models/cluster/dataprotection/fullname.go rename to internal/models/dataprotection/cluster/dataprotection/fullname.go index 7b5370356..9cf3d550f 100644 --- a/internal/models/cluster/dataprotection/fullname.go +++ b/internal/models/dataprotection/cluster/dataprotection/fullname.go @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MPL-2.0 */ -package dataprotectionmodels +package dataprotectionclustermodels import ( "github.com/go-openapi/swag" diff --git a/internal/models/cluster/dataprotection/requests.go b/internal/models/dataprotection/cluster/dataprotection/requests.go similarity index 98% rename from internal/models/cluster/dataprotection/requests.go rename to internal/models/dataprotection/cluster/dataprotection/requests.go index e16ec944a..2173276d9 100644 --- a/internal/models/cluster/dataprotection/requests.go +++ b/internal/models/dataprotection/cluster/dataprotection/requests.go @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MPL-2.0 */ -package dataprotectionmodels +package dataprotectionclustermodels import ( "github.com/go-openapi/swag" diff --git a/internal/models/cluster/dataprotection/spec.go b/internal/models/dataprotection/cluster/dataprotection/spec.go similarity index 97% rename from internal/models/cluster/dataprotection/spec.go rename to internal/models/dataprotection/cluster/dataprotection/spec.go index 37d96e72b..ffdec512a 100644 --- a/internal/models/cluster/dataprotection/spec.go +++ b/internal/models/dataprotection/cluster/dataprotection/spec.go @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MPL-2.0 */ -package dataprotectionmodels +package dataprotectionclustermodels import ( "github.com/go-openapi/swag" diff --git a/internal/models/cluster/dataprotection/status.go b/internal/models/dataprotection/cluster/dataprotection/status.go similarity index 98% rename from internal/models/cluster/dataprotection/status.go rename to internal/models/dataprotection/cluster/dataprotection/status.go index f5b63d05c..23f75cdac 100644 --- a/internal/models/cluster/dataprotection/status.go +++ b/internal/models/dataprotection/cluster/dataprotection/status.go @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MPL-2.0 */ -package dataprotectionmodels +package dataprotectionclustermodels import ( "github.com/go-openapi/swag" diff --git a/internal/models/cluster/dataprotection/status_phase.go b/internal/models/dataprotection/cluster/dataprotection/status_phase.go similarity index 99% rename from internal/models/cluster/dataprotection/status_phase.go rename to internal/models/dataprotection/cluster/dataprotection/status_phase.go index 8457254bb..398ab22c3 100644 --- a/internal/models/cluster/dataprotection/status_phase.go +++ b/internal/models/dataprotection/cluster/dataprotection/status_phase.go @@ -3,7 +3,7 @@ Copyright © 2023 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: MPL-2.0 */ -package dataprotectionmodels +package dataprotectionclustermodels import ( "encoding/json" diff --git a/internal/models/dataprotection/cluster/targetlocation/access_mode.go b/internal/models/dataprotection/cluster/targetlocation/access_mode.go new file mode 100644 index 000000000..9008d4250 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/access_mode.go @@ -0,0 +1,51 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "encoding/json" +) + +// VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode The permissions for a BackupStorageLocation. +// +// - READONLY: The read only access. +// - READWRITE: Read and write access. +// +// swagger:model vmware.tanzu.manage.v1alpha1.cluster.dataprotection.backuplocation.Status.BackupStorageLocationAccessMode. +type VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode string + +func NewVmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode(value VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode) *VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode { + return &value +} + +// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode. +func (m VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode) Pointer() *VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode { + return &m +} + +const ( + + // VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADONLY captures enum value "READONLY". + VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADONLY VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode = "READONLY" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADWRITE captures enum value "READWRITE". + VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeREADWRITE VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode = "READWRITE" +) + +// for schema. +var vmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeEnum []interface{} + +func init() { + var res []VmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessMode + + if err := json.Unmarshal([]byte(`["READONLY","READWRITE"]`), &res); err != nil { + panic(err) + } + + for _, v := range res { + vmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeEnum = append(vmwareTanzuManageV1alpha1ClusterDataprotectionBackuplocationStatusBackupStorageLocationAccessModeEnum, v) + } +} diff --git a/internal/models/dataprotection/cluster/targetlocation/assigned_groups.go b/internal/models/dataprotection/cluster/targetlocation/assigned_groups.go new file mode 100644 index 000000000..154b13381 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/assigned_groups.go @@ -0,0 +1,47 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "github.com/go-openapi/swag" + + clustermodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster" + clustergroupmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/clustergroup" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup Group of resources the backup location will be assigned to. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.AssignedGroup. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup struct { + + // Full name of a cluster. + Cluster *clustermodel.VmwareTanzuManageV1alpha1ClusterFullName `json:"cluster,omitempty"` + + // Full name of a cluster group. + Clustergroup *clustergroupmodel.VmwareTanzuManageV1alpha1ClustergroupFullName `json:"clustergroup,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/backup_location.go b/internal/models/dataprotection/cluster/targetlocation/backup_location.go new file mode 100644 index 000000000..10eef4d52 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/backup_location.go @@ -0,0 +1,55 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "github.com/go-openapi/swag" + + objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation A target location for backups. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.BackupLocation. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation struct { + + // Full name for the BackupLocation. + FullName *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationFullName `json:"fullName,omitempty"` + + // Metadata for the backup location object. + Meta *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta `json:"meta,omitempty"` + + // Spec for the backup location. + Spec *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationSpec `json:"spec,omitempty"` + + // Status of the backup location. + Status *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatus `json:"status,omitempty"` + + // Metadata describing the type of the resource. + Type *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectType `json:"type,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/config.go b/internal/models/dataprotection/cluster/targetlocation/config.go new file mode 100644 index 000000000..bd6ed4e07 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/config.go @@ -0,0 +1,121 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import "github.com/go-openapi/swag" + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderSpecificConfig Provider specific configuration for backup location (https://github.com/heptio/velero/blob/master/docs/api-types/backupstoragelocation.md). +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.TargetProviderSpecificConfig. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderSpecificConfig struct { + + // Azure specific config. + AzureConfig *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAzureStorageConfiguration `json:"azureConfig,omitempty"` + + // S3 and S3-compatible config. + S3Config *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationS3Configuration `json:"s3Config,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderSpecificConfig) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderSpecificConfig) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderSpecificConfig + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// ### Azure Config ### + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAzureStorageConfiguration Azure specific storage configuration details. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.AzureStorageConfiguration. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAzureStorageConfiguration struct { + + // Name of the resource group containing the storage account for this backup storage location. + ResourceGroup string `json:"resourceGroup,omitempty"` + + // Name of the storage account for this backup storage location. + StorageAccount string `json:"storageAccount,omitempty"` + + // Subscription ID under which all the resources are being managed in azure. Optional. + SubscriptionID string `json:"subscriptionId,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAzureStorageConfiguration) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAzureStorageConfiguration) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAzureStorageConfiguration + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// ### AWS Config ### + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationS3Configuration AWS S3 or other S3-compatible storage configuration details. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.S3Configuration. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationS3Configuration struct { + + // The service endpoint used for generating download URLs. This field is primarily for local storage services like Minio. + PublicURL string `json:"publicUrl,omitempty"` + + // A flag for whether to force path style URLs for S3 objects. It is default to false and set it to true when. + // using local storage service like Minio. + S3ForcePathStyle bool `json:"s3ForcePathStyle"` + + // The service endpoint for non-AWS S3 storage solution. + S3URL string `json:"s3Url,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationS3Configuration) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationS3Configuration) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationS3Configuration + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/fullname.go b/internal/models/dataprotection/cluster/targetlocation/fullname.go new file mode 100644 index 000000000..ae33f7ac6 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/fullname.go @@ -0,0 +1,48 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationFullName Full name of the resource. This includes the object name along. +// with any parents or further identifiers. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.FullName. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationFullName struct { + + // Name of the Backup Location. + Name string `json:"name,omitempty"` + + // ID of Organization. + OrgID string `json:"orgId,omitempty"` + + // Name of the data protection provider name. + ProviderName string `json:"providerName,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationFullName) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationFullName) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationFullName + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/list_backup_locations_search_scope.go b/internal/models/dataprotection/cluster/targetlocation/list_backup_locations_search_scope.go new file mode 100644 index 000000000..763327929 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/list_backup_locations_search_scope.go @@ -0,0 +1,48 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import "github.com/go-openapi/swag" + +// !!! NOT GENERATED BY SWAGGER !!!. + +type ListBackupLocationsSearchScope struct { + ProviderName string `json:"providerName,omitempty"` + + Name string `json:"name,omitempty"` + + CredentialName string `json:"credentialName,omitempty"` + + AssignedGroupName string `json:"assignedGroupName,omitempty"` + + ClusterName string `json:"clusterName,omitempty"` + + ManagementClusterName string `json:"managementClusterName,omitempty"` + + ProvisionerName string `json:"provisionerName,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *ListBackupLocationsSearchScope) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *ListBackupLocationsSearchScope) UnmarshalBinary(b []byte) error { + var res ListBackupLocationsSearchScope + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/requests.go b/internal/models/dataprotection/cluster/targetlocation/requests.go new file mode 100644 index 000000000..bbf5b3bb4 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/requests.go @@ -0,0 +1,144 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationCreateBackupLocationRequest Request to create a BackupLocation. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.CreateBackupLocationRequest. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationCreateBackupLocationRequest struct { + + // BackupLocation to create. + BackupLocation *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation `json:"backupLocation,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationCreateBackupLocationRequest) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationCreateBackupLocationRequest) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationCreateBackupLocationRequest + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationCreateBackupLocationResponse Response from creating a BackupLocation. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.CreateBackupLocationResponse. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationResponse struct { + + // BackupLocation created. + BackupLocation *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation `json:"backupLocation,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationResponse + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationListBackupLocationsResponse Response from listing BackupLocations. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.ListBackupLocationsResponse. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationListBackupLocationsResponse struct { + + // List of backuplocations. + BackupLocations []*VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationBackupLocation `json:"backupLocations"` + + // Total count. + TotalCount string `json:"totalCount,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationListBackupLocationsResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationListBackupLocationsResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationListBackupLocationsResponse + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// !!! NOT GENERATED BY SWAGGER !!!. + +type ListBackupLocationsRequest struct { + // Scope can be provider or cluster. + SearchScope *ListBackupLocationsSearchScope `json:"searchScope"` + + // Sort results by. + SortBy string `json:"sortBy,omitempty"` + + // Query to run against the API. + Query string `json:"query,omitempty"` + + // Include Total. + IncludeTotalCount bool `json:"includeTotal"` +} + +// MarshalBinary interface implementation. +func (m *ListBackupLocationsRequest) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *ListBackupLocationsRequest) UnmarshalBinary(b []byte) error { + var res ListBackupLocationsRequest + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/spec.go b/internal/models/dataprotection/cluster/targetlocation/spec.go new file mode 100644 index 000000000..c19c44ded --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/spec.go @@ -0,0 +1,61 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "github.com/go-openapi/swag" + + credentialsmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/credential" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationSpec The backup location spec. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.Spec. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationSpec struct { + + // List of groups the backup location will be assigned to. + AssignedGroups []*VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationAssignedGroup `json:"assignedGroups"` + + // The bucket to use for object storage. + Bucket string `json:"bucket,omitempty"` + + // A PEM-encoded certificate bundle to trust while connecting to the storage backend. Optional. + CaCert string `json:"caCert,omitempty"` + + // Provider-specific storage configuration fields. + Config *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderSpecificConfig `json:"config"` + + // The name of credential to be used to access the bucket. + Credential *credentialsmodel.VmwareTanzuManageV1alpha1AccountCredentialFullName `json:"credential,omitempty"` + + // The region of the bucket origin. Optional. + Region string `json:"region,omitempty"` + + // The target provider of the backup storage. + TargetProvider *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider `json:"targetProvider,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationSpec) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationSpec + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/status.go b/internal/models/dataprotection/cluster/targetlocation/status.go new file mode 100644 index 000000000..02b06a9fd --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/status.go @@ -0,0 +1,58 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "github.com/go-openapi/swag" + + statusmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/status" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatus Status of the backup location resource. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.Status. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatus struct { + + // A list of available phases for backup location object. + AvailablePhases []*VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase `json:"availablePhases"` + + // The Conditions attached to a backup location. + Conditions map[string]statusmodel.VmwareTanzuCoreV1alpha1StatusCondition `json:"conditions,omitempty"` + + // The resource generation the current status applies to. + ObservedGeneration string `json:"observedGeneration,omitempty"` + + // The overall phase of the backup location. + Phase *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase `json:"phase,omitempty"` + + // Additional info about the phase. + PhaseInfo string `json:"phaseInfo,omitempty"` + + // Type of the backup location. + Type *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType `json:"type,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatus) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatus + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/cluster/targetlocation/status_phase.go b/internal/models/dataprotection/cluster/targetlocation/status_phase.go new file mode 100644 index 000000000..458a32142 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/status_phase.go @@ -0,0 +1,75 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "encoding/json" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase Available phases for backup location object. +// +// - PHASE_UNSPECIFIED: Phase_unspecified is the default phase. +// - PENDING: Pending phase is set when the backup location object is being processed by the service (TMC). +// - CREATING: Creating phase is set when backup location is being created by the service. +// - PENDING_DELETE: Pending delete is set when the backup location delete is being processed by the service. +// - DELETING: Deleting the set when the backup location delete is in progress. +// - READY: Ready phase is set when the backup location is successfully created. +// - ERROR: Error phase is set when there was a failure while creating/deleting backup location. +// - UPDATING: Updating the set when the backup location is being updated. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.Status.Phase. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase string + +func NewVmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase(value VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase) *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase { + return &value +} + +// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase. +func (m VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase) Pointer() *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase { + return &m +} + +const ( + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhasePHASEUNSPECIFIED captures enum value "PHASE_UNSPECIFIED". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhasePHASEUNSPECIFIED VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "PHASE_UNSPECIFIED" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhasePENDING captures enum value "PENDING". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhasePENDING VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "PENDING" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseCREATING captures enum value "CREATING". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseCREATING VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "CREATING" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhasePENDINGDELETE captures enum value "PENDING_DELETE". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhasePENDINGDELETE VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "PENDING_DELETE" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseDELETING captures enum value "DELETING". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseDELETING VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "DELETING" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseREADY captures enum value "READY". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseREADY VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "READY" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseERROR captures enum value "ERROR". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseERROR VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "ERROR" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseUPDATING captures enum value "UPDATING". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseUPDATING VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase = "UPDATING" +) + +// for schema. +var vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseEnum []interface{} + +func init() { + var res []VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhase + + if err := json.Unmarshal([]byte(`["PHASE_UNSPECIFIED","PENDING","CREATING","PENDING_DELETE","DELETING","READY","ERROR","UPDATING"]`), &res); err != nil { + panic(err) + } + + for _, v := range res { + vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseEnum = append(vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusPhaseEnum, v) + } +} diff --git a/internal/models/dataprotection/cluster/targetlocation/status_type.go b/internal/models/dataprotection/cluster/targetlocation/status_type.go new file mode 100644 index 000000000..076337355 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/status_type.go @@ -0,0 +1,55 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "encoding/json" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType Type of the backup location. +// +// - TYPE_UNSPECIFIED: Type Unspecified is the default type for a backup location. +// - MANAGED: Type MANAGED indicates backup location(bucket) is managed by TMC. +// - UNMANAGED: UNMANAGED indicates backup location(bucket) is not managed by TMC. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.Status.Type. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType string + +func NewVmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType(value VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType) *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType { + return &value +} + +// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType. +func (m VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType) Pointer() *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType { + return &m +} + +const ( + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeTYPEUNSPECIFIED captures enum value "TYPE_UNSPECIFIED". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeTYPEUNSPECIFIED VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType = "TYPE_UNSPECIFIED" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeMANAGED captures enum value "MANAGED". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeMANAGED VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType = "MANAGED" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeUNMANAGED captures enum value "UNMANAGED". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeUNMANAGED VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType = "UNMANAGED" +) + +// for schema. +var vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeEnum []interface{} + +func init() { + var res []VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusType + + if err := json.Unmarshal([]byte(`["TYPE_UNSPECIFIED","MANAGED","UNMANAGED"]`), &res); err != nil { + panic(err) + } + + for _, v := range res { + vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeEnum = append(vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationStatusTypeEnum, v) + } +} diff --git a/internal/models/dataprotection/cluster/targetlocation/target_provider.go b/internal/models/dataprotection/cluster/targetlocation/target_provider.go new file mode 100644 index 000000000..e19f3d230 --- /dev/null +++ b/internal/models/dataprotection/cluster/targetlocation/target_provider.go @@ -0,0 +1,55 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package targetlocationmodels + +import ( + "encoding/json" +) + +// VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider Available target provider for back up locations. +// +// - TARGET_PROVIDER_UNSPECIFIED: Unspecified target provider. +// - AWS: AWS. +// - AZURE: AZURE. +// +// swagger:model vmware.tanzu.manage.v1alpha1.dataprotection.provider.backuplocation.TargetProvider. +type VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider string + +func NewVmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider(value VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider) *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider { + return &value +} + +// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider. +func (m VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider) Pointer() *VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider { + return &m +} + +const ( + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderTARGETPROVIDERUNSPECIFIED captures enum value "TARGET_PROVIDER_UNSPECIFIED". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderTARGETPROVIDERUNSPECIFIED VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider = "TARGET_PROVIDER_UNSPECIFIED" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderAWS captures enum value "AWS". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderAWS VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider = "AWS" + + // VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderAZURE captures enum value "AZURE". + VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderAZURE VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider = "AZURE" +) + +// for schema. +var vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderEnum []interface{} + +func init() { + var res []VmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProvider + + if err := json.Unmarshal([]byte(`["TARGET_PROVIDER_UNSPECIFIED","AWS","AZURE"]`), &res); err != nil { + panic(err) + } + + for _, v := range res { + vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderEnum = append(vmwareTanzuManageV1alpha1DataprotectionProviderBackuplocationTargetProviderEnum, v) + } +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/data_protection.go b/internal/models/dataprotection/clustergroup/dataprotection/data_protection.go new file mode 100644 index 000000000..54fb98d26 --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/data_protection.go @@ -0,0 +1,58 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" + + objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection Backup, restore, or migrate cluster group data. +// +// Protect Kubernetes cluster group data with the DataProtection resource. Backup, restore, or. +// migrate cluster objects and volumes. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.DataProtection. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection struct { + + // Full name for the DataProtection. + FullName *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName `json:"fullName,omitempty"` + + // Metadata for the DataProtection object. + Meta *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta `json:"meta,omitempty"` + + // Spec field for DataProtection. + Spec *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpec `json:"spec"` + + // Status field. + Status *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatus `json:"status,omitempty"` + + // Metadata describing the type of the resource. + Type *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectType `json:"type,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/fullname.go b/internal/models/dataprotection/clustergroup/dataprotection/fullname.go new file mode 100644 index 000000000..67f59eb38 --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/fullname.go @@ -0,0 +1,44 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName Full name of the namespace. This includes the object name along. +// with any parents or further identifiers. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.FullName. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName struct { + // ID of Organization. + OrgID string `json:"orgId,omitempty"` + + // Name of Cluster group. + ClusterGroupName string `json:"cluster_group_name,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionFullName + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/label_selector.go b/internal/models/dataprotection/clustergroup/dataprotection/label_selector.go new file mode 100644 index 000000000..bd4fb5596 --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/label_selector.go @@ -0,0 +1,53 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelectorLabelSelector Label based Selector. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.spec.selector.labelselector +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelectorLabelSelector struct { + // key is the label key that the selector applies to. + // +patchMergeKey=key + // +patchStrategy=merge + Key string `json:"key,omitempty"` + + // operator represents a key's relationship to a set of values. + // Valid operators are In, NotIn, Exists and DoesNotExist. + Operator string `json:"operator,omitempty"` + + // values is an array of string values. If the operator is In or NotIn, + // the values array must be non-empty. If the operator is Exists or DoesNotExist, + // the values array must be empty. This array is replaced during a strategic + // merge patch. + // +optional + Values []string `json:"values"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelectorLabelSelector) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelectorLabelSelector) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelectorLabelSelector + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/requests.go b/internal/models/dataprotection/clustergroup/dataprotection/requests.go new file mode 100644 index 000000000..b1175e039 --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/requests.go @@ -0,0 +1,106 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest Request to create a DataProtection. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.CreateDataProtectionRequest. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest struct { + + // DataProtection to create. + DataProtection *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection `json:"dataProtection,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionRequest + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse Response from creating a DataProtection. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.CreateDataProtectionResponse. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse struct { + + // DataProtection created. + DataProtection *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection `json:"dataProtection,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionCreateDataProtectionResponse + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse Response from listing DataProtections. +// +// swagger:model vmware.tanzu.manage.v1alpha1.cluster.dataprotection.ListDataProtectionsResponse. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse struct { + + // List of dataprotections. + DataProtections []*VmwareTanzuManageV1alpha1ClusterGroupDataprotectionDataProtection `json:"dataProtections"` + + // Total count. + TotalCount string `json:"totalCount,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionListDataProtectionsResponse + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/selector.go b/internal/models/dataprotection/clustergroup/dataprotection/selector.go new file mode 100644 index 000000000..1aff8bc05 --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/selector.go @@ -0,0 +1,46 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelector The Selector to include/exclude specific targets. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.Spec.Selector +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelector struct { + // List of target names to include. + Names []string `json:"names,omitempty"` + + // List of target names to exclude. + ExcludedNames []string `json:"excluded_names,omitempty"` + + // Label based Selector. + LabelSelector *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelectorLabelSelector `json:"label_selector,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelector) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelector) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelector + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/spec.go b/internal/models/dataprotection/clustergroup/dataprotection/spec.go new file mode 100644 index 000000000..92cc58167 --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/spec.go @@ -0,0 +1,60 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpec The spec collects all the options for installing backup and restore solution into a cluster group. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.Spec. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpec struct { + // A flag to indicate whether to skip installation of restic server (https://github.com/restic/restic). + // Otherwise, restic would be enabled by default as part of Data Protection installation. + DisableRestic bool `json:"disableRestic"` + + // A flag to indicate whether to backup all the supported API Group versions of a resource on the cluster. + EnableAllAPIGroupVersionsBackup bool `json:"enableAllApiGroupVersionsBackup"` + + // List of Backup Locations to install in the cluster. + BackupLocationNames []string `json:"backup_location_names,omitempty"` + + // A flag to indicate whether to backup all the supported API Group versions of a resource on the cluster. + EnableAllApiGroupVersionsBackup bool `json:"enable_all_api_group_versions_backup,omitempty"` + + // A flag to indicate whether to install CSI snapshotting related capabilities. + EnableCsiSnapshots bool `json:"enableCsiSnapshots"` + + // A flag to indicate whether to install the node agent daemonset which is responsible for data transfer + // to the target location. + UseNodeAgent bool `json:"use_node_agent,omitempty"` + + // Selector to include/exclude specific clusters (optional). + Selector *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpecSelector `json:"selector,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpec) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionSpec + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/status.go b/internal/models/dataprotection/clustergroup/dataprotection/status.go new file mode 100644 index 000000000..595ae64eb --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/status.go @@ -0,0 +1,46 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatus Status of the DataProtection configure resource. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.Status. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatus struct { + // Generation value at the time this status was updated. + ObservedGeneration string `json:"observedGeneration,omitempty"` + + // Phase of the Cluster Group Data Protection on member Clusters. + Phase *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase `json:"phase,omitempty"` + + // Details contains information about the Cluster Group Data Protection being applied on member Clusters. + Details *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusDetails `json:"details,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatus) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatus + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/status_details.go b/internal/models/dataprotection/clustergroup/dataprotection/status_details.go new file mode 100644 index 000000000..583739160 --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/status_details.go @@ -0,0 +1,52 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusDetails Status of the DataProtection configure resource. +// +// swagger:model vmware.tanzu.manage.v1alpha1.clustergroup.dataprotection.Status.details +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusDetails struct { + // Total number of targets available for this source resource. + AvailableTargets int32 `json:"available_targets,omitempty"` + // Number of atomic targets on which this source resource is successfully applied. + Applied int32 `json:"applied,omitempty"` + // Number of atomic targets on which this source resource is overridden by another resource. + Overridden int32 `json:"overridden,omitempty"` + // Number of atomic targets on which this source resource is still being applied. + Pending int32 `json:"pending,omitempty"` + // Number of atomic targets on which this source resource failed to apply due to some error. + Error int32 `json:"error,omitempty"` + // Number of atomic targets on which this source resource is currently being deleted (only applicable on some source resource types). + Deleting int32 `json:"deleting,omitempty"` + // Number of atomic targets on which this source resource is not applied because they don't match the provided selectors. + Skipped int32 `json:"skipped,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusDetails) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusDetails) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusDetails + + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/dataprotection/clustergroup/dataprotection/status_phase.go b/internal/models/dataprotection/clustergroup/dataprotection/status_phase.go new file mode 100644 index 000000000..262905b4f --- /dev/null +++ b/internal/models/dataprotection/clustergroup/dataprotection/status_phase.go @@ -0,0 +1,75 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package dataprotectionclustergroupmodels + +import ( + "encoding/json" +) + +// VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase Available phases for data protection object. +// +// - PHASE_UNSPECIFIED: Phase_unspecified is the default phase. +// - PENDING: Pending phase is set when the data protection object is being processed by the service (TMC). +// - CREATING: Creating phase is set when data protection is being enabled on the cluster group. +// - PENDING_DELETE: Pending delete is set when the data protection delete is being processed by the service. +// - DELETING: Deleting the set when the data protection delete is in progress on the cluster group. +// - READY: Ready phase is set when the data protection is successfully enabled. +// - ERROR: Error phase is set when there was a failure while creating/deleting data protection. +// - UPDATING: Updating is set when the data protection is being updated. +// +// swagger:model vmware.tanzu.manage.v1alpha1.cluster.dataprotection.Status.Phase. +type VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase string + +func NewVmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase(value VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase) *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase { + return &value +} + +// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhase. +func (m VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase) Pointer() *VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase { + return &m +} + +const ( + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhasePHASEUNSPECIFIED captures enum value "PHASE_UNSPECIFIED". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhasePHASEUNSPECIFIED VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "PHASE_UNSPECIFIED" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhasePENDING captures enum value "PENDING". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhasePENDING VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "PENDING" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseCREATING captures enum value "CREATING". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseCREATING VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "CREATING" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhasePENDINGDELETE captures enum value "PENDING_DELETE". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhasePENDINGDELETE VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "PENDING_DELETE" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseDELETING captures enum value "DELETING". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseDELETING VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "DELETING" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseREADY captures enum value "READY". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseREADY VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "READY" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseERROR captures enum value "ERROR". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseERROR VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "ERROR" + + // VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseUPDATING captures enum value "UPDATING". + VmwareTanzuManageV1alpha1ClusterDataprotectionStatusPhaseUPDATING VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase = "UPDATING" +) + +// for schema. +var vmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhaseEnum []interface{} + +func init() { + var res []VmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhase + + if err := json.Unmarshal([]byte(`["PHASE_UNSPECIFIED","PENDING","CREATING","PENDING_DELETE","DELETING","READY","ERROR","UPDATING"]`), &res); err != nil { + panic(err) + } + + for _, v := range res { + vmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhaseEnum = append(vmwareTanzuManageV1alpha1ClusterGroupDataprotectionStatusPhaseEnum, v) + } +} diff --git a/internal/resources/cluster/backupschedule/converter_mapping.go b/internal/resources/cluster/backupschedule/converter_mapping.go index 82759a562..194732b78 100644 --- a/internal/resources/cluster/backupschedule/converter_mapping.go +++ b/internal/resources/cluster/backupschedule/converter_mapping.go @@ -7,7 +7,7 @@ package backupschedule import ( tfModelConverterHelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper/converter" - backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule" + backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/backupschedule" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common" ) diff --git a/internal/resources/cluster/backupschedule/datasource_backup_schedule.go b/internal/resources/cluster/backupschedule/datasource_backup_schedule.go index 858491c96..38508c5fe 100644 --- a/internal/resources/cluster/backupschedule/datasource_backup_schedule.go +++ b/internal/resources/cluster/backupschedule/datasource_backup_schedule.go @@ -14,7 +14,7 @@ import ( "github.com/pkg/errors" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx" - backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule" + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/backupschedule" ) func DataSourceBackupSchedule() *schema.Resource { diff --git a/internal/resources/cluster/backupschedule/resource_backup_schedule.go b/internal/resources/cluster/backupschedule/resource_backup_schedule.go index d46fccd4a..f9985c414 100644 --- a/internal/resources/cluster/backupschedule/resource_backup_schedule.go +++ b/internal/resources/cluster/backupschedule/resource_backup_schedule.go @@ -18,7 +18,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" - backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule" + backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/backupschedule" ) func ResourceBackupSchedule() *schema.Resource { diff --git a/internal/resources/cluster/backupschedule/resource_schema.go b/internal/resources/cluster/backupschedule/resource_schema.go index 3cc57cec1..245317fae 100644 --- a/internal/resources/cluster/backupschedule/resource_schema.go +++ b/internal/resources/cluster/backupschedule/resource_schema.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule" + backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/backupschedule" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common" ) diff --git a/internal/resources/cluster/backupschedule/tests/backup_schedule_test.go b/internal/resources/cluster/backupschedule/tests/backup_schedule_test.go index b6577dff1..b1e017bcc 100644 --- a/internal/resources/cluster/backupschedule/tests/backup_schedule_test.go +++ b/internal/resources/cluster/backupschedule/tests/backup_schedule_test.go @@ -20,7 +20,7 @@ import ( "github.com/vmware/terraform-provider-tanzu-mission-control/internal/authctx" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/proxy" - backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/backupschedule" + backupschedulemodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/dataprotection/cluster/backupschedule" backupscheduleres "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/cluster/backupschedule" testhelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/testing" ) From e8f6454d13bbfefbc00ffa9cf374525f1d2aef09 Mon Sep 17 00:00:00 2001 From: mshobha Date: Thu, 16 Nov 2023 14:23:09 +0530 Subject: [PATCH 2/2] Schema changes Signed-off-by: mshobha --- .../dataprotection/dataprotection_resource.go | 2 +- internal/provider/provider.go | 4 +- .../backupschedule/tests/helper_test.go | 4 +- .../tests/resource_tf_configs.go | 2 +- .../dataprotection/converter_mapping.go | 2 +- .../resource_enable_data_protection.go | 25 ++++++- .../{cluster => }/dataprotection/schema.go | 4 +- .../resources/dataprotection/scope/cluster.go | 50 ++++++++++++++ .../dataprotection/scope/cluster_group.go | 40 +++++++++++ .../resources/dataprotection/scope/scope.go | 68 +++++++++++++++++++ .../tests/enable_data_protection_test.go | 0 .../dataprotection/tests/helper_test.go | 6 +- .../tests/resource_tf_configs.go | 2 +- .../tests/datasource_tf_configs.go | 2 +- .../targetlocation/tests/helper_test.go | 4 +- 15 files changed, 198 insertions(+), 17 deletions(-) rename internal/resources/{cluster => }/dataprotection/converter_mapping.go (95%) rename internal/resources/{cluster => }/dataprotection/resource_enable_data_protection.go (91%) rename internal/resources/{cluster => }/dataprotection/schema.go (91%) create mode 100644 internal/resources/dataprotection/scope/cluster.go create mode 100644 internal/resources/dataprotection/scope/cluster_group.go create mode 100644 internal/resources/dataprotection/scope/scope.go rename internal/resources/{cluster => }/dataprotection/tests/enable_data_protection_test.go (100%) rename internal/resources/{cluster => }/dataprotection/tests/helper_test.go (78%) rename internal/resources/{cluster => }/dataprotection/tests/resource_tf_configs.go (97%) diff --git a/internal/client/cluster/dataprotection/dataprotection_resource.go b/internal/client/cluster/dataprotection/dataprotection_resource.go index e2859229e..7b1b7c066 100644 --- a/internal/client/cluster/dataprotection/dataprotection_resource.go +++ b/internal/client/cluster/dataprotection/dataprotection_resource.go @@ -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 ( diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 260b3e19e..1297e43ad 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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" "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" @@ -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{ diff --git a/internal/resources/cluster/backupschedule/tests/helper_test.go b/internal/resources/cluster/backupschedule/tests/helper_test.go index ad10cb468..02fd70a3e 100644 --- a/internal/resources/cluster/backupschedule/tests/helper_test.go +++ b/internal/resources/cluster/backupschedule/tests/helper_test.go @@ -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" @@ -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" ) @@ -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{ diff --git a/internal/resources/cluster/backupschedule/tests/resource_tf_configs.go b/internal/resources/cluster/backupschedule/tests/resource_tf_configs.go index e82c6dd60..3066abce1 100644 --- a/internal/resources/cluster/backupschedule/tests/resource_tf_configs.go +++ b/internal/resources/cluster/backupschedule/tests/resource_tf_configs.go @@ -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" diff --git a/internal/resources/cluster/dataprotection/converter_mapping.go b/internal/resources/dataprotection/converter_mapping.go similarity index 95% rename from internal/resources/cluster/dataprotection/converter_mapping.go rename to internal/resources/dataprotection/converter_mapping.go index b88d10272..b5bad80c3 100644 --- a/internal/resources/cluster/dataprotection/converter_mapping.go +++ b/internal/resources/dataprotection/converter_mapping.go @@ -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" ) diff --git a/internal/resources/cluster/dataprotection/resource_enable_data_protection.go b/internal/resources/dataprotection/resource_enable_data_protection.go similarity index 91% rename from internal/resources/cluster/dataprotection/resource_enable_data_protection.go rename to internal/resources/dataprotection/resource_enable_data_protection.go index 00cc1d896..36f2c380e 100644 --- a/internal/resources/cluster/dataprotection/resource_enable_data_protection.go +++ b/internal/resources/dataprotection/resource_enable_data_protection.go @@ -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" @@ -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 { @@ -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 := + } } request := &dataprotectionmodels.VmwareTanzuManageV1alpha1ClusterDataprotectionCreateDataProtectionRequest{ diff --git a/internal/resources/cluster/dataprotection/schema.go b/internal/resources/dataprotection/schema.go similarity index 91% rename from internal/resources/cluster/dataprotection/schema.go rename to internal/resources/dataprotection/schema.go index a21db9902..7cb7e9f09 100644 --- a/internal/resources/cluster/dataprotection/schema.go +++ b/internal/resources/dataprotection/schema.go @@ -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 ( @@ -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{ diff --git a/internal/resources/dataprotection/scope/cluster.go b/internal/resources/dataprotection/scope/cluster.go new file mode 100644 index 000000000..6d2ad0b58 --- /dev/null +++ b/internal/resources/dataprotection/scope/cluster.go @@ -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} +} diff --git a/internal/resources/dataprotection/scope/cluster_group.go b/internal/resources/dataprotection/scope/cluster_group.go new file mode 100644 index 000000000..52c9d9af2 --- /dev/null +++ b/internal/resources/dataprotection/scope/cluster_group.go @@ -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} +} diff --git a/internal/resources/dataprotection/scope/scope.go b/internal/resources/dataprotection/scope/scope.go new file mode 100644 index 000000000..74e757ca8 --- /dev/null +++ b/internal/resources/dataprotection/scope/scope.go @@ -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 +} diff --git a/internal/resources/cluster/dataprotection/tests/enable_data_protection_test.go b/internal/resources/dataprotection/tests/enable_data_protection_test.go similarity index 100% rename from internal/resources/cluster/dataprotection/tests/enable_data_protection_test.go rename to internal/resources/dataprotection/tests/enable_data_protection_test.go diff --git a/internal/resources/cluster/dataprotection/tests/helper_test.go b/internal/resources/dataprotection/tests/helper_test.go similarity index 78% rename from internal/resources/cluster/dataprotection/tests/helper_test.go rename to internal/resources/dataprotection/tests/helper_test.go index 82912f81c..032e88916 100644 --- a/internal/resources/cluster/dataprotection/tests/helper_test.go +++ b/internal/resources/dataprotection/tests/helper_test.go @@ -9,6 +9,7 @@ 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" @@ -16,7 +17,6 @@ import ( "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" ) @@ -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, } diff --git a/internal/resources/cluster/dataprotection/tests/resource_tf_configs.go b/internal/resources/dataprotection/tests/resource_tf_configs.go similarity index 97% rename from internal/resources/cluster/dataprotection/tests/resource_tf_configs.go rename to internal/resources/dataprotection/tests/resource_tf_configs.go index 7a36997f3..5d8f86501 100644 --- a/internal/resources/cluster/dataprotection/tests/resource_tf_configs.go +++ b/internal/resources/dataprotection/tests/resource_tf_configs.go @@ -7,10 +7,10 @@ package dataprotectiontests import ( "fmt" + dataprotectionres "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" ) diff --git a/internal/resources/targetlocation/tests/datasource_tf_configs.go b/internal/resources/targetlocation/tests/datasource_tf_configs.go index 232d5a5a4..4b40c00a3 100644 --- a/internal/resources/targetlocation/tests/datasource_tf_configs.go +++ b/internal/resources/targetlocation/tests/datasource_tf_configs.go @@ -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" ) diff --git a/internal/resources/targetlocation/tests/helper_test.go b/internal/resources/targetlocation/tests/helper_test.go index 4d54cb4e4..0b3a2ef12 100644 --- a/internal/resources/targetlocation/tests/helper_test.go +++ b/internal/resources/targetlocation/tests/helper_test.go @@ -9,6 +9,7 @@ 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" @@ -16,7 +17,6 @@ import ( "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" @@ -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(),