-
Notifications
You must be signed in to change notification settings - Fork 116
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
f0693ea
commit 2fefb07
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package lcm | ||
|
||
import ( | ||
"github.com/nutanix/ntnx-api-golang-clients/lifecycle-go-client/v4/api" | ||
lcm "github.com/nutanix/ntnx-api-golang-clients/lifecycle-go-client/v4/client" | ||
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client" | ||
) | ||
|
||
type Client struct { | ||
LcmConfigAPIInstance *api.ConfigApi | ||
} | ||
|
||
func NewLCMClient(credentials client.Credentials) (*Client, error) { | ||
var baseClient *lcm.ApiClient | ||
|
||
// check if all required fields are present. Else create an empty client | ||
if credentials.Username != "" && credentials.Password != "" && credentials.Endpoint != "" { | ||
pcClient := lcm.NewApiClient() | ||
|
||
pcClient.Host = credentials.Endpoint | ||
pcClient.Password = credentials.Password | ||
pcClient.Username = credentials.Username | ||
pcClient.Port = 9440 | ||
pcClient.VerifySSL = false | ||
|
||
baseClient = pcClient | ||
} | ||
|
||
f := &Client{ | ||
LcmConfigAPIInstance: api.NewConfigApi(baseClient), | ||
} | ||
|
||
return f, nil | ||
} |
86 changes: 86 additions & 0 deletions
86
nutanix/services/lcmv2/data_source_lcm_configuration_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,86 @@ | ||
package lcmv2 | ||
|
||
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 DatasourceNutanixLcmConfigrationV2() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: DatasourceNutanixLcmConfigrationV2Read, | ||
Schema: map[string]*schema.Schema{ | ||
"cluster_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"ext_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"links": schemaForLinks(), | ||
}, | ||
} | ||
} | ||
|
||
func DatasourceNutanixLcmConfigrationV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.Client).PrismAPI | ||
|
||
domainManagerExtID := d.Get("domain_manager_ext_id").(string) | ||
backupTargetExtID := d.Get("ext_id").(string) | ||
|
||
resp, err := conn.DomainManagerBackupsAPIInstance.GetBackupTargetById(utils.StringPtr(domainManagerExtID), utils.StringPtr(backupTargetExtID), nil) | ||
|
||
if err != nil { | ||
return diag.Errorf("error while fetching Backup Target: %s", err) | ||
} | ||
|
||
backupTarget := resp.Data.GetValue().(management.BackupTarget) | ||
|
||
if err := d.Set("tenant_id", backupTarget.TenantId); err != nil { | ||
return diag.Errorf("error setting tenant_id: %s", err) | ||
} | ||
if err := d.Set("ext_id", backupTarget.ExtId); err != nil { | ||
return diag.Errorf("error setting ext_id: %s", err) | ||
} | ||
if err := d.Set("links", flattenLinks(backupTarget.Links)); err != nil { | ||
return diag.Errorf("error setting links: %s", err) | ||
} | ||
if err := d.Set("last_sync_time", flattenTime(backupTarget.LastSyncTime)); err != nil { | ||
return diag.Errorf("error setting last_sync_time: %s", err) | ||
} | ||
if err := d.Set("is_backup_paused", backupTarget.IsBackupPaused); err != nil { | ||
return diag.Errorf("error setting is_backup_paused: %s", err) | ||
} | ||
if err := d.Set("backup_pause_reason", backupTarget.BackupPauseReason); err != nil { | ||
return diag.Errorf("error setting backup_pause_reason: %s", err) | ||
} | ||
if err := d.Set("location", flattenBackupTargetLocation(backupTarget.Location)); err != nil { | ||
return diag.Errorf("error setting location: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func schemaForLinks() *schema.Schema { | ||
return &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"rel": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"href": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |