From 0a5dac5cba085adf4475934b0fb88860fda29651 Mon Sep 17 00:00:00 2001 From: graysonwu Date: Thu, 25 Jan 2024 19:21:03 -0800 Subject: [PATCH] Expose extended attribute in realization info Signed-off-by: graysonwu --- ...ata_source_nsxt_policy_realization_info.go | 29 +++++++++++++++++++ .../d/policy_realization_info.html.markdown | 11 ++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/nsxt/data_source_nsxt_policy_realization_info.go b/nsxt/data_source_nsxt_policy_realization_info.go index f07263c00..afc127fb1 100644 --- a/nsxt/data_source_nsxt_policy_realization_info.go +++ b/nsxt/data_source_nsxt_policy_realization_info.go @@ -34,6 +34,20 @@ func dataSourceNsxtPolicyRealizationInfo() *schema.Resource { Computed: true, Optional: true, }, + "extended_attribute_key": { + Type: schema.TypeString, + Description: "The extended attribute key of the realized resource. ", + Optional: true, + RequiredWith: []string{"entity_type"}, + }, + "extended_attribute_value": { + Type: schema.TypeList, + Description: "The extended attribute values according to the extended_attribute_key of the realized resource", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + }, "state": { Type: schema.TypeString, Description: "The state of the realized resource", @@ -75,6 +89,7 @@ func dataSourceNsxtPolicyRealizationInfoRead(d *schema.ResourceData, m interface // Get the realization info of this resource path := d.Get("path").(string) entityType := d.Get("entity_type").(string) + extAttKey := d.Get("extended_attribute_key").(string) objSitePath := d.Get("site_path").(string) delay := d.Get("delay").(int) timeout := d.Get("timeout").(int) @@ -126,6 +141,20 @@ func dataSourceNsxtPolicyRealizationInfoRead(d *schema.ResourceData, m interface } return realizationResult, state, nil } else if (objInList.EntityType != nil) && (*objInList.EntityType == entityType) { + if extAttKey != "" { + found := false + for _, extAtt := range objInList.ExtendedAttributes { + // Take the first one + if extAtt.Key != nil && *extAtt.Key == extAttKey { + d.Set("extended_attribute_value", extAtt.Values) + found = true + break + } + } + if !found { + continue + } + } d.Set("state", state) if objInList.RealizationSpecificIdentifier == nil { d.Set("realized_id", "") diff --git a/website/docs/d/policy_realization_info.html.markdown b/website/docs/d/policy_realization_info.html.markdown index 5b285999d..3fffe48ff 100644 --- a/website/docs/d/policy_realization_info.html.markdown +++ b/website/docs/d/policy_realization_info.html.markdown @@ -19,9 +19,10 @@ data "nsxt_policy_tier1_gateway" "tier1_gw" { } data "nsxt_policy_realization_info" "info" { - path = data.nsxt_policy_tier1_gateway.tier1_gw.path - entity_type = "RealizedLogicalRouter" - timeout = 60 + path = data.nsxt_policy_tier1_gateway.tier1_gw.path + entity_type = "RealizedLogicalRouterPort" + extended_attribute_key = "IpAddresses" + timeout = 60 } ``` @@ -67,12 +68,13 @@ data "nsxt_policy_realization_info" "info" { ## Argument Reference * `path` - (Required) The policy path of the resource. -* `entity_type` - (Optional) The entity type of realized resource. If not set, on of the realized resources of the policy resource will be retrieved. +* `entity_type` - (Optional) The entity type of realized resource. If not set, one of the realized resources of the policy resource will be retrieved. * `site_path` - (Optional) The path of the site which the resource belongs to, this configuration is required for global manager only. `path` field of the existing `nsxt_policy_site` can be used here. * `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. * `context` - (Optional) The context which the object belongs to * `project_id` - (Required) The ID of the project which the object belongs to +* `extended_attribute_key` - (Optional) The extended attribute key of specific type entity of realized resource. It can only be provided, when `entity_type` is specified. ## Attributes Reference @@ -80,3 +82,4 @@ In addition to arguments listed above, the following attributes are exported: * `state` - The realization state of the resource: "REALIZED", "UNKNOWN", "UNREALIZED" or "ERROR". * `realized_id` - The id of the realized object. +* `extended_attribute_value` - The value of corresponding `extended_attribute_key` that is provided.