-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #949 from ksamoray/xportnode_realization
Transport node realization data source
- Loading branch information
Showing
4 changed files
with
173 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* Copyright © 2023 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/model" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/transport_nodes" | ||
) | ||
|
||
func dataSourceNsxtTransportNodeRealization() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceNsxtTransportNodeRealizationRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Unique ID of this resource", | ||
}, | ||
"timeout": { | ||
Type: schema.TypeInt, | ||
Description: "Realization timeout in seconds", | ||
Optional: true, | ||
Default: 1200, | ||
ValidateFunc: validation.IntAtLeast(1), | ||
}, | ||
"delay": { | ||
Type: schema.TypeInt, | ||
Description: "Initial delay to start realization checks in seconds", | ||
Optional: true, | ||
Default: 1, | ||
ValidateFunc: validation.IntAtLeast(0), | ||
}, | ||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Overall state of desired configuration", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNsxtTransportNodeRealizationRead(d *schema.ResourceData, m interface{}) error { | ||
connector := getPolicyConnector(m) | ||
client := transport_nodes.NewStateClient(connector) | ||
|
||
id := d.Get("id").(string) | ||
delay := d.Get("delay").(int) | ||
timeout := d.Get("timeout").(int) | ||
|
||
pendingStates := []string{ | ||
model.TransportNodeState_STATE_PENDING, | ||
model.TransportNodeState_STATE_IN_PROGRESS, | ||
model.TransportNodeState_STATE_IN_SYNC, | ||
model.TransportNodeState_STATE_UNKNOWN, | ||
} | ||
targetStates := []string{ | ||
model.TransportNodeState_STATE_SUCCESS, | ||
model.TransportNodeState_STATE_FAILED, | ||
model.TransportNodeState_STATE_PARTIAL_SUCCESS, | ||
model.TransportNodeState_STATE_ORPHANED, | ||
model.TransportNodeState_STATE_ERROR, | ||
} | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: pendingStates, | ||
Target: targetStates, | ||
Refresh: func() (interface{}, string, error) { | ||
state, err := client.Get(id) | ||
if err != nil { | ||
return state, model.TransportNodeState_STATE_ERROR, logAPIError("Error while waiting for realization of transport node", err) | ||
} | ||
|
||
log.Printf("[DEBUG] Current realization state for Transport Node %s is %s", id, *state.State) | ||
|
||
d.Set("state", state.State) | ||
return state, *state.State, nil | ||
}, | ||
Timeout: time.Duration(timeout) * time.Second, | ||
MinTimeout: 1 * time.Second, | ||
Delay: time.Duration(delay) * time.Second, | ||
} | ||
_, err := stateConf.WaitForState() | ||
if err != nil { | ||
return fmt.Errorf("failed to get realization information for %s: %v", id, err) | ||
} | ||
|
||
return nil | ||
} |
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,75 @@ | ||
--- | ||
subcategory: "Realization" | ||
layout: "nsxt" | ||
page_title: "NSXT: transport_node_realization" | ||
description: Transport node resource realization information. | ||
--- | ||
|
||
# nsxt_transport_node_realization | ||
|
||
This data source provides information about the realization of a transport node resource on NSX manager. This data source will wait until realization is determined as either success or error. It is recommended to use this data source if further configuration depends on transport node realization. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "nsxt_transport_node" "test" { | ||
description = "Terraform-deployed edge node" | ||
display_name = "tf_edge_node" | ||
standard_host_switch { | ||
host_switch_mode = "STANDARD" | ||
host_switch_type = "NVDS" | ||
ip_assignment { | ||
static_ip_pool_id = data.nsxt_ip_pool.ipp1.id | ||
} | ||
transport_zone_endpoint { | ||
transport_zone_id = data.nsxt_transport_zone.tz1.id | ||
transport_zone_profile_id = ["52035bb3-ab02-4a08-9884-18631312e50a"] | ||
} | ||
host_switch_profile_id = [nsxt_uplink_host_switch_profile.hsw_profile1.id] | ||
is_migrate_pnics = false | ||
pnics { | ||
device_name = "fp-eth0" | ||
uplink_name = "uplink1" | ||
} | ||
} | ||
edge_node { | ||
deployment_config { | ||
form_factor = "SMALL" | ||
node_user_settings { | ||
cli_password = "some_cli_password" | ||
root_password = "some_other_password" | ||
} | ||
vm_deployment_config { | ||
management_network_id = data.vsphere_network.network1.id | ||
data_network_ids = [data.vsphere_network.network1.id] | ||
compute_id = data.vsphere_compute_cluster.compute_cluster1.id | ||
storage_id = data.vsphere_datastore.datastore1.id | ||
vc_id = nsxt_compute_manager.vc1.id | ||
host_id = data.vsphere_host.host1.id | ||
} | ||
} | ||
node_settings { | ||
hostname = "tf_edge_node" | ||
allow_ssh_root_login = true | ||
enable_ssh = true | ||
} | ||
} | ||
} | ||
data "nsxt_transport_node_realization" "test" { | ||
id = nsxt_transport_node.test.id | ||
timeout = 60 | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `id` - (Required) ID of the resource. | ||
* `delay` - (Optional) Delay (in seconds) before realization polling is started. Default is set to 1. | ||
* `timeout` - (Optional) Timeout (in seconds) for realization polling. Default is set to 1200. | ||
|
||
## Attributes Reference | ||
|
||
In addition to arguments listed above, the following attributes are exported: | ||
|
||
* `state` - The realization state of the resource. Transitional states are: "pending", "in_progress", "in_sync", "unknown". Target states are: "success", "failed", "partial_success", "orphaned", "error". |
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