-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7401ace
commit ee7737d
Showing
3 changed files
with
294 additions
and
40 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
nutanix/services/prismv2/data_source_restore_point_v2.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
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/config" | ||
"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 DatasourceNutanixFetchRestorePointV2() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: DatasourceNutanixRestorePointV2Read, | ||
Schema: map[string]*schema.Schema{ | ||
"restore_source_ext_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"restorable_domain_manager_ext_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"ext_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"tenant_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"links": schemaForLinks(), | ||
"creation_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"domain_manager": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"tenant_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ext_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"config": schemaForPcConfig(), | ||
"is_registered_with_hosting_cluster": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"network": schemaForPcNetwork(), | ||
"hosting_cluster_ext_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"should_enable_high_availability": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"node_ext_ids": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func DatasourceNutanixRestorePointV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.Client).PrismAPI | ||
|
||
restoreSourceExtID := utils.StringPtr(d.Get("restore_source_ext_id").(string)) | ||
restorableDomainManagerExtID := utils.StringPtr(d.Get("restorable_domain_manager_ext_id").(string)) | ||
extID := utils.StringPtr(d.Get("ext_id").(string)) | ||
|
||
resp, err := conn.DomainManagerBackupsAPIInstance.GetRestorePointById(restoreSourceExtID, restorableDomainManagerExtID, extID) | ||
|
||
if err != nil { | ||
return diag.Errorf("error while fetching Domain Manager Restore Point Detail: %s", err) | ||
} | ||
|
||
restorePoint := resp.Data.GetValue().(management.RestorePoint) | ||
|
||
if err := d.Set("tenant_id", utils.StringValue(restorePoint.TenantId)); err != nil { | ||
return diag.Errorf("error setting tenant_id: %s", err) | ||
} | ||
if err := d.Set("links", flattenLinks(restorePoint.Links)); err != nil { | ||
return diag.Errorf("error setting links: %s", err) | ||
} | ||
if err := d.Set("creation_time", flattenTime(restorePoint.CreationTime)); err != nil { | ||
return diag.Errorf("error setting creation_time: %s", err) | ||
} | ||
if err := d.Set("domain_manager", flattenDomainManager(restorePoint.DomainManager)); err != nil { | ||
return diag.Errorf("error setting domain_manager: %s", err) | ||
} | ||
return nil | ||
} | ||
|
||
func flattenDomainManager(domainManager *config.DomainManager) []map[string]interface{} { | ||
if domainManager == nil { | ||
return nil | ||
} | ||
|
||
return []map[string]interface{}{ | ||
{ | ||
"tenant_id": utils.StringValue(domainManager.TenantId), | ||
"ext_id": utils.StringValue(domainManager.ExtId), | ||
"config": flattenPCConfig(domainManager.Config), | ||
"is_registered_with_hosting_cluster": utils.BoolValue(domainManager.IsRegisteredWithHostingCluster), | ||
"network": flattenPCNetwork(domainManager.Network), | ||
"hosting_cluster_ext_id": utils.StringValue(domainManager.HostingClusterExtId), | ||
"should_enable_high_availability": utils.BoolValue(domainManager.ShouldEnableHighAvailability), | ||
"node_ext_ids": domainManager.NodeExtIds, | ||
}, | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
nutanix/services/prismv2/data_source_restore_points_v2.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package prismv2 | ||
|
||
import ( | ||
"context" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"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 DatasourceNutanixFetchRestorePointsV2() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: DatasourceNutanixRestorePointsV2Read, | ||
Schema: map[string]*schema.Schema{ | ||
"restore_source_ext_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"restorable_domain_manager_ext_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"page": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 0, | ||
ValidateFunc: validation.IntAtLeast(0), | ||
}, | ||
"limit": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 50, | ||
ValidateFunc: validation.IntBetween(1, 100), | ||
}, | ||
"filter": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"order_by": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"select": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"restore_points": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: DatasourceNutanixFetchRestorePointV2(), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func DatasourceNutanixRestorePointsV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.Client).PrismAPI | ||
|
||
restoreSourceExtID := utils.StringPtr(d.Get("restore_source_ext_id").(string)) | ||
restorableDomainManagerExtID := utils.StringPtr(d.Get("restorable_domain_manager_ext_id").(string)) | ||
|
||
var selects, orderBy, filter *string | ||
var page, limit *int | ||
|
||
if selectf, ok := d.GetOk("select"); ok { | ||
selects = utils.StringPtr(selectf.(string)) | ||
} else { | ||
selects = nil | ||
} | ||
if orderByf, ok := d.GetOk("order_by"); ok { | ||
orderBy = utils.StringPtr(orderByf.(string)) | ||
} else { | ||
orderBy = nil | ||
} | ||
if filterf, ok := d.GetOk("filter"); ok { | ||
filter = utils.StringPtr(filterf.(string)) | ||
} else { | ||
filter = nil | ||
} | ||
if pagef, ok := d.GetOk("page"); ok { | ||
page = utils.IntPtr(pagef.(int)) | ||
} else { | ||
page = nil | ||
} | ||
if limitf, ok := d.GetOk("limit"); ok { | ||
limit = utils.IntPtr(limitf.(int)) | ||
} else { | ||
limit = nil | ||
} | ||
|
||
resp, err := conn.DomainManagerBackupsAPIInstance.ListRestorePoints(restoreSourceExtID, restorableDomainManagerExtID, page, limit, filter, orderBy, selects) | ||
|
||
if err != nil { | ||
return diag.Errorf("error while fetching Domain Manager Restore Point Detail: %s", err) | ||
} | ||
|
||
if resp.Data == nil { | ||
if err := d.Set("restore_points", []map[string]interface{}{}); err != nil { | ||
return diag.Errorf("Error setting restore_points: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
restorePoints := resp.Data.GetValue().([]management.RestorePoint) | ||
|
||
if err := d.Set("restore_points", flattenRestorePoints(restorePoints)); err != nil { | ||
return diag.Errorf("Error setting restore_points: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func flattenRestorePoints(restorePoints []management.RestorePoint) []map[string]interface{} { | ||
restorePointsList := make([]map[string]interface{}, 0) | ||
for _, restorePoint := range restorePoints { | ||
restorePointMap := map[string]interface{}{ | ||
"tenant_id": utils.StringValue(restorePoint.TenantId), | ||
"ext_id": utils.StringValue(restorePoint.ExtId), | ||
"links": flattenLinks(restorePoint.Links), | ||
"creation_time": flattenTime(restorePoint.CreationTime), | ||
"domain_manager": flattenDomainManager(restorePoint.DomainManager), | ||
} | ||
restorePointsList = append(restorePointsList, restorePointMap) | ||
} | ||
return restorePointsList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters