Skip to content

Commit

Permalink
restore source info dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroon-Dweikat-Ntx committed Dec 16, 2024
1 parent 48a6def commit 4c798f5
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
140 changes: 140 additions & 0 deletions nutanix/services/prismv2/data_source_restore_source_v2.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4c798f5

Please sign in to comment.