Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose network_name in segment realization data #308

Merged
merged 3 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions nsxt/data_source_nsxt_policy_segment_realization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
},
},
}
}
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions nsxt/data_source_nsxt_policy_segment_realization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand Down
9 changes: 8 additions & 1 deletion website/docs/d/policy_segment_realization.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.