From 778ded5fd2c5e4deea5b2d65225e8f5bb6eb8641 Mon Sep 17 00:00:00 2001 From: Anna Khmelnitsky Date: Tue, 9 Mar 2021 21:37:37 +0000 Subject: [PATCH] Introduce timeout and delay realization parameters Realization data source can now be fine-tuned with two new params: * delay defines wait time befor realization polling begins * timeout defines the timeout for realization polling --- ...ata_source_nsxt_policy_realization_info.go | 21 +++++++++++++++++-- .../d/policy_realization_info.html.markdown | 6 +++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/nsxt/data_source_nsxt_policy_realization_info.go b/nsxt/data_source_nsxt_policy_realization_info.go index 3c434dcbe..ec3d15157 100644 --- a/nsxt/data_source_nsxt_policy_realization_info.go +++ b/nsxt/data_source_nsxt_policy_realization_info.go @@ -9,6 +9,7 @@ import ( "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" gm_realized_state "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/realized_state" gm_model "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/realized_state" @@ -49,6 +50,20 @@ func dataSourceNsxtPolicyRealizationInfo() *schema.Resource { Optional: true, ValidateFunc: validatePolicyPath(), }, + "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), + }, }, } } @@ -61,6 +76,8 @@ func dataSourceNsxtPolicyRealizationInfoRead(d *schema.ResourceData, m interface path := d.Get("path").(string) entityType := d.Get("entity_type").(string) objSitePath := d.Get("site_path").(string) + delay := d.Get("delay").(int) + timeout := d.Get("timeout").(int) // Site is mandatory got GM and irrelevant else if !isPolicyGlobalManager(m) && objSitePath != "" { @@ -136,9 +153,9 @@ func dataSourceNsxtPolicyRealizationInfoRead(d *schema.ResourceData, m interface } return realizationResult, "", realizationError }, - Timeout: d.Timeout(schema.TimeoutCreate), + Timeout: time.Duration(timeout) * time.Second, MinTimeout: 1 * time.Second, - Delay: 1 * time.Second, + Delay: time.Duration(delay) * time.Second, } _, err := stateConf.WaitForState() if err != nil { diff --git a/website/docs/d/policy_realization_info.html.markdown b/website/docs/d/policy_realization_info.html.markdown index 6996c09ec..2021b13e8 100644 --- a/website/docs/d/policy_realization_info.html.markdown +++ b/website/docs/d/policy_realization_info.html.markdown @@ -21,6 +21,7 @@ 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 } ``` @@ -45,15 +46,14 @@ 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. - * `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. ## 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.