Skip to content

Commit

Permalink
Manager version data source
Browse files Browse the repository at this point in the history
Retrieves the version of the manager datasource.

Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed May 1, 2024
1 parent e76412f commit f9976f3
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_version.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"

Check warning on line 12 in nsxt/data_source_nsxt_version.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: const nsxVersionId should be nsxVersionID (revive)

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
}
29 changes: 29 additions & 0 deletions nsxt/data_source_nsxt_version_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 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"),
),
},
},
})
}
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_version": dataSourceNsxtVersion(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
20 changes: 20 additions & 0 deletions website/docs/d/version.html.markdown
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit f9976f3

Please sign in to comment.