diff --git a/nsxt/data_source_nsxt_policy_segment_realization.go b/nsxt/data_source_nsxt_policy_segment_realization.go index 9ee93efe6..6f23860bd 100644 --- a/nsxt/data_source_nsxt_policy_segment_realization.go +++ b/nsxt/data_source_nsxt_policy_segment_realization.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" "time" @@ -29,6 +30,11 @@ func dataSourceNsxtPolicySegmentRealization() *schema.Resource { Description: "The state of the realized resource on hypervisors", Computed: true, }, + "network_name": { + Type: schema.TypeString, + Description: "Network name on the hypervisors", + Computed: true, + }, }, } } @@ -82,5 +88,16 @@ func dataSourceNsxtPolicySegmentRealizationRead(d *schema.ResourceData, m interf return fmt.Errorf("Failed to get realization information for %s: %v", path, err) } + // We need to fetch network name to use in vpshere provider. However, state API does not + // return it in details yet. For now, we'll use segment display name, since its always + // translates to network name + segClient := infra.NewDefaultSegmentsClient(connector) + obj, err := segClient.Get(segmentID) + if err != nil { + return handleReadError(d, "Segment", segmentID, err) + } + + d.Set("network_name", obj.DisplayName) + return nil } diff --git a/nsxt/data_source_nsxt_policy_segment_realization_test.go b/nsxt/data_source_nsxt_policy_segment_realization_test.go index 141697f04..903985c24 100644 --- a/nsxt/data_source_nsxt_policy_segment_realization_test.go +++ b/nsxt/data_source_nsxt_policy_segment_realization_test.go @@ -20,6 +20,7 @@ func testAccDataSourceNsxtPolicySegmentRealization(t *testing.T, vlan bool) { Config: testAccNsxtPolicySegmentRealizationTemplate(vlan), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(testResourceName, "state", "success"), + resource.TestCheckResourceAttr(testResourceName, "network_name", "terra-test"), resource.TestCheckResourceAttrSet(testResourceName, "path"), ), }, diff --git a/website/docs/d/policy_segment_realization.html.markdown b/website/docs/d/policy_segment_realization.html.markdown index 8837bb4b1..4deee5ef4 100644 --- a/website/docs/d/policy_segment_realization.html.markdown +++ b/website/docs/d/policy_segment_realization.html.markdown @@ -20,9 +20,15 @@ resource "nsxt_policy_segment" "s1" { transport_zone_path = data.nsxt_transport_zone.tz1.path } -data "nsxt_policy_segment_realization" "info" { +data "nsxt_policy_segment_realization" "s1" { path = data.nsxt_policy_segment.s1.path } + +# usage in vsphere provider +data "vsphere_network" "net" { + name = nsxt_policy_segment_realization.s1.network_name + datacenter_id = data.vsphere_datacenter.datacenter.id +} ``` ## Argument Reference @@ -34,3 +40,4 @@ data "nsxt_policy_segment_realization" "info" { In addition to arguments listed above, the following attributes are exported: * `state` - The realization state of the resource: `success`, `partial_success`, `orphaned`, `failed` or `error`. +* `network_name` - Network name on the hypervisor. This attribute can be used in vsphere provider in order to ensure implicit dependency on segment realization.