From ae1ce63b17c84361960c2e50a5272a0b33bef0f1 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Thu, 11 Apr 2024 13:39:52 +0300 Subject: [PATCH] Manager info data source A container for various information about the NSX manager. For now, retrieves the software version of the manager. Signed-off-by: Kobi Samoray --- nsxt/data_source_nsxt_manager_info.go | 37 ++++++++++++++++++++++ nsxt/data_source_nsxt_manager_info_test.go | 29 +++++++++++++++++ nsxt/provider.go | 1 + website/docs/d/manager_info.html.markdown | 20 ++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 nsxt/data_source_nsxt_manager_info.go create mode 100644 nsxt/data_source_nsxt_manager_info_test.go create mode 100644 website/docs/d/manager_info.html.markdown diff --git a/nsxt/data_source_nsxt_manager_info.go b/nsxt/data_source_nsxt_manager_info.go new file mode 100644 index 000000000..6a65fa6ad --- /dev/null +++ b/nsxt/data_source_nsxt_manager_info.go @@ -0,0 +1,37 @@ +/* Copyright © 2024 Broadcom, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +const nsxVersionID = "nsxversion" + +func dataSourceNsxtManagerInfo() *schema.Resource { + return &schema.Resource{ + Read: dataSourceNsxtManagerInfoRead, + Schema: map[string]*schema.Schema{ + "version": { + Type: schema.TypeString, + Description: "Version of NSXT manager", + Computed: true, + }, + }, + } +} + +func dataSourceNsxtManagerInfoRead(d *schema.ResourceData, m interface{}) error { + connector := getPolicyConnector(m) + version, err := getNSXVersion(connector) + if err != nil { + return fmt.Errorf("failed to retrieve NSX version: %v", err) + } + d.Set("version", version) + d.SetId(nsxVersionID) + + return nil +} diff --git a/nsxt/data_source_nsxt_manager_info_test.go b/nsxt/data_source_nsxt_manager_info_test.go new file mode 100644 index 000000000..b2f9663a9 --- /dev/null +++ b/nsxt/data_source_nsxt_manager_info_test.go @@ -0,0 +1,29 @@ +/* Copyright © 2024 Broadcom, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceNsxtManagerInfo_basic(t *testing.T) { + testResourceName := "data.nsxt_manager_info.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: ` +data "nsxt_manager_info" "test" { +}`, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(testResourceName, "version"), + ), + }, + }, + }) +} diff --git a/nsxt/provider.go b/nsxt/provider.go index 8681a2859..8beb5962a 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -324,6 +324,7 @@ func Provider() *schema.Provider { "nsxt_policy_vtep_ha_host_switch_profile": dataSourceNsxtVtepHAHostSwitchProfile(), "nsxt_policy_distributed_flood_protection_profile": dataSourceNsxtPolicyDistributedFloodProtectionProfile(), "nsxt_policy_gateway_flood_protection_profile": dataSourceNsxtPolicyGatewayFloodProtectionProfile(), + "nsxt_manager_info": dataSourceNsxtManagerInfo(), }, ResourcesMap: map[string]*schema.Resource{ diff --git a/website/docs/d/manager_info.html.markdown b/website/docs/d/manager_info.html.markdown new file mode 100644 index 000000000..ca7c16ff4 --- /dev/null +++ b/website/docs/d/manager_info.html.markdown @@ -0,0 +1,20 @@ +--- +subcategory: "Manager" +layout: "nsxt" +page_title: "nsxt_manager_info" +description: A NSX-T manager information data source. +--- + +# nsxt_manager_info + +This data source provides various information about the NSX-T manager. + +## Example Usage + +```hcl +data "nsxt_manager_info" "cluster" {} +``` + +## Attributes Reference + +* `version` - The software version of the NSX-T manager node.