From f9976f3e6478d6033f030916f455a6b5f6a2b516 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Thu, 11 Apr 2024 13:39:52 +0300 Subject: [PATCH] Manager version data source Retrieves the version of the manager datasource. Signed-off-by: Kobi Samoray --- nsxt/data_source_nsxt_version.go | 37 +++++++++++++++++++++++++++ nsxt/data_source_nsxt_version_test.go | 29 +++++++++++++++++++++ nsxt/provider.go | 1 + website/docs/d/version.html.markdown | 20 +++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 nsxt/data_source_nsxt_version.go create mode 100644 nsxt/data_source_nsxt_version_test.go create mode 100644 website/docs/d/version.html.markdown diff --git a/nsxt/data_source_nsxt_version.go b/nsxt/data_source_nsxt_version.go new file mode 100644 index 000000000..5d5b64e7e --- /dev/null +++ b/nsxt/data_source_nsxt_version.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 dataSourceNsxtVersion() *schema.Resource { + return &schema.Resource{ + Read: dataSourceNsxtVersionRead, + Schema: map[string]*schema.Schema{ + "version": { + Type: schema.TypeString, + Description: "Version of NSXT manager", + Computed: true, + }, + }, + } +} + +func dataSourceNsxtVersionRead(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_version_test.go b/nsxt/data_source_nsxt_version_test.go new file mode 100644 index 000000000..6ba2d714a --- /dev/null +++ b/nsxt/data_source_nsxt_version_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 TestAccDataSourceNsxtVersion_basic(t *testing.T) { + testResourceName := "data.nsxt_version.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: ` +data "nsxt_version" "test" { +}`, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(testResourceName, "version"), + ), + }, + }, + }) +} diff --git a/nsxt/provider.go b/nsxt/provider.go index 8681a2859..ff7798426 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_version": dataSourceNsxtVersion(), }, ResourcesMap: map[string]*schema.Resource{ diff --git a/website/docs/d/version.html.markdown b/website/docs/d/version.html.markdown new file mode 100644 index 000000000..7d877d038 --- /dev/null +++ b/website/docs/d/version.html.markdown @@ -0,0 +1,20 @@ +--- +subcategory: "Manager" +layout: "nsxt" +page_title: "nsxt_version" +description: A NSX-T version data source. +--- + +# nsxt_version + +This data source provides the version of the NSX-T manager. + +## Example Usage + +```hcl +data "nsxt_version" "cluster" {} +``` + +## Attributes Reference + +* `version` - The software version of the NSX-T manager node.