Skip to content

Commit

Permalink
Expose extended attribute in realization info
Browse files Browse the repository at this point in the history
Signed-off-by: graysonwu <[email protected]>
  • Loading branch information
GraysonWu committed Jan 31, 2024
1 parent f1e5494 commit 0a5dac5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
29 changes: 29 additions & 0 deletions nsxt/data_source_nsxt_policy_realization_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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", "")
Expand Down
11 changes: 7 additions & 4 deletions website/docs/d/policy_realization_info.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down Expand Up @@ -67,16 +68,18 @@ 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

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.

0 comments on commit 0a5dac5

Please sign in to comment.