From 4c798f573621d54b34f67896ad1601d5fa561876 Mon Sep 17 00:00:00 2001 From: Haroon-Dweikat-Ntx Date: Mon, 16 Dec 2024 16:15:33 +0200 Subject: [PATCH] restore source info dev --- nutanix/provider/provider.go | 2 + .../prismv2/data_source_restore_source_v2.go | 140 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 nutanix/services/prismv2/data_source_restore_source_v2.go diff --git a/nutanix/provider/provider.go b/nutanix/provider/provider.go index a9982450..5628faac 100644 --- a/nutanix/provider/provider.go +++ b/nutanix/provider/provider.go @@ -267,6 +267,7 @@ func Provider() *schema.Provider { "nutanix_storage_container_stats_info_v2": storagecontainersv2.DatasourceNutanixStorageStatsInfoV2(), "nutanix_category_v2": prismv2.DatasourceNutanixCategoryV2(), "nutanix_categories_v2": prismv2.DatasourceNutanixCategoriesV2(), + "nutanix_restore_source_v2": prismv2.DatasourceNutanixRestoreSourceV2(), "nutanix_volume_groups_v2": volumesv2.DatasourceNutanixVolumeGroupsV2(), "nutanix_volume_group_v2": volumesv2.DatasourceNutanixVolumeGroupV2(), "nutanix_volume_group_disks_v2": volumesv2.DatasourceNutanixVolumeDisksV2(), @@ -362,6 +363,7 @@ func Provider() *schema.Provider { "nutanix_deploy_pc_v2": prismv2.ResourceNutanixDeployPcV2(), "nutanix_unregister_cluster_v2": prismv2.ResourceNutanixUnregisterClusterV2(), "nutanix_backup_target_v2": prismv2.ResourceNutanixBackupTargetV2(), + "nutanix_restore_source_v2": prismv2.ResourceNutanixRestoreSourceV2(), "nutanix_volume_group_v2": volumesv2.ResourceNutanixVolumeGroupV2(), "nutanix_volume_group_disk_v2": volumesv2.ResourceNutanixVolumeGroupDiskV2(), "nutanix_volume_group_iscsi_client_v2": volumesv2.ResourceNutanixVolumeGroupIscsiClientV2(), diff --git a/nutanix/services/prismv2/data_source_restore_source_v2.go b/nutanix/services/prismv2/data_source_restore_source_v2.go new file mode 100644 index 00000000..e3027222 --- /dev/null +++ b/nutanix/services/prismv2/data_source_restore_source_v2.go @@ -0,0 +1,140 @@ +package prismv2 + +import ( + "context" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/models/prism/v4/management" + conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix" + "github.com/terraform-providers/terraform-provider-nutanix/utils" +) + +func DatasourceNutanixRestoreSourceV2() *schema.Resource { + return &schema.Resource{ + ReadContext: DatasourceNutanixRestoreSourceV2Read, + Schema: map[string]*schema.Schema{ + "ext_id": { + Type: schema.TypeString, + Required: true, + }, + "tenant_id": { + Type: schema.TypeString, + Computed: true, + }, + "links": schemaForLinks(), + "location": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cluster_location": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "config": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ext_id": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "object_store_location": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "provider_config": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bucket_name": { + Type: schema.TypeString, + Computed: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + }, + "credentials": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "access_key_id": { + Type: schema.TypeString, + Computed: true, + }, + "secret_access_key": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "backup_policy": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rpo_in_minutes": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func DatasourceNutanixRestoreSourceV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.Client).PrismAPI + + restoreSourceExtID := d.Get("ext_id").(string) + + resp, err := conn.DomainManagerBackupsAPIInstance.GetRestoreSourceById(utils.StringPtr(restoreSourceExtID), nil) + + if err != nil { + return diag.Errorf("error while fetching Restore Source: %s", err) + } + + restoreSource := resp.Data.GetValue().(management.RestoreSource) + + if err := d.Set("tenant_id", restoreSource.TenantId); err != nil { + return diag.Errorf("error setting tenant_id: %s", err) + } + if err := d.Set("ext_id", restoreSource.ExtId); err != nil { + return diag.Errorf("error setting ext_id: %s", err) + } + if err := d.Set("links", flattenLinks(restoreSource.Links)); err != nil { + return diag.Errorf("error setting links: %s", err) + } + if err := d.Set("location", flattenRestoreSourceLocation(restoreSource.Location)); err != nil { + return diag.Errorf("error setting location: %s", err) + } + + return nil +}