Skip to content

Commit

Permalink
Merge pull request #1201 from ksamoray/ds-nsx-version
Browse files Browse the repository at this point in the history
Manager info data source
  • Loading branch information
ksamoray authored May 10, 2024
2 parents 94a5c97 + ae1ce63 commit a8cdeae
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
37 changes: 37 additions & 0 deletions nsxt/data_source_nsxt_manager_info.go
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions nsxt/data_source_nsxt_manager_info_test.go
Original file line number Diff line number Diff line change
@@ -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"),
),
},
},
})
}
1 change: 1 addition & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
20 changes: 20 additions & 0 deletions website/docs/d/manager_info.html.markdown
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit a8cdeae

Please sign in to comment.