Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor resources to align with VCD and TM tests #1355

Merged
merged 24 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .changes/v4.0.0/1343-features.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
* **New Resource:** `vcd_vcenter` to manage vCenter servers [GH-1343, GH-1348]
* **New Resource:** `vcd_nsxt_manager` to manage NSX-T Managers [GH-1343]
* **New Resource:** `vcd_tm_vcenter` to manage TM vCenter servers [GH-1343, GH-1348, GH-1355]
* **New Data Source:** `vcd_tm_vcenter` to read TM vCenter servers [GH-1355]
* **New Resource:** `vcd_tm_nsxt_manager` to manage NSX-T Managers [GH-1343, GH-1355]
* **New Data Source:** `vcd_tm_nsxt_manager` to manage NSX-T Managers [GH-1343, GH-1355]
1 change: 1 addition & 0 deletions .changes/v4.0.0/1353-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* Improve scripts for TM test support - `make testtm-acc`, `testtm-acc-coverage`, `make
testtm-binary`, `make testtm-binary-prepare` [GH-1353]
* Add `make testacc-coverage` VCD acceptance test run with coverage [GH-1355]
* Adjusts `TESTING.md` for TM testing [GH-1353]
* Splits sample test configs to `sample_vcd_test_config.json` for VCD and
`sample_vcd_test_config_tm.json` for TM [GH-1353]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ website/node_modules
*.cover

vcd/vcd_test_config*.json
vcd_test_config*.json
vcd/go-vcloud-director.log
vcd/test-artifacts
website/vendor
Expand Down
4 changes: 4 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ testacc-orguser: testunit
testacc: testunit
@sh -c "'$(CURDIR)/scripts/runtest.sh' acceptance"

# Runs the full acceptance test as system administrator
testacc-coverage: testunit
@sh -c "'$(CURDIR)/scripts/runtest.sh' acceptance-coverage"

# Runs the acceptance test for tm
testtm-acc: fmtcheck testunit
@sh -c "'$(CURDIR)/scripts/runtest.sh' tm-acceptance"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/kr/pretty v0.3.1
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.6
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.7
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.6 h1:gCv8L2S9kIbgIiwmiX3Pip+BChuyMAB/XqSKUsFF3Og=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.6/go.mod h1:68KHsVns52dsq/w5JQYzauaU/+NAi1FmCxhBrFc/VoQ=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.7 h1:puIYeYmnPOisLptusccwNQKXVMS930Ja6KTyhjvqTow=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.7/go.mod h1:68KHsVns52dsq/w5JQYzauaU/+NAi1FmCxhBrFc/VoQ=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
13 changes: 8 additions & 5 deletions scripts/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ function check_for_config_file {
function unit_test {
if [ -n "$VERBOSE" ]
then
echo "go test -race -tags unit ${TEST} || exit 1"
echo "go test -race -tags unit -v -timeout 5m"
echo "go test -tags unit ${TEST} || exit 1"
echo "go test -tags unit -v -timeout 5m"
fi
if [ -z "$DRY_RUN" ]
then
go test -race -tags unit ${TEST} || exit 1
go test -race -tags unit -v -timeout 5m
go test -tags unit ${TEST} || exit 1
go test -tags unit -v -timeout 5m
fi
}

Expand Down Expand Up @@ -378,7 +378,10 @@ case $wanted in
acceptance_test functional
;;
acceptance)
acceptance_test functional
acceptance_test "unit functional"
;;
acceptance-coverage)
acceptance_test "unit functional" "-coverprofile testacc.cover"
;;
sequential-acceptance)
acceptance_test functional "-race --parallel=1"
Expand Down
5 changes: 5 additions & 0 deletions vcd/datasource_not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vcd
import (
"fmt"
"regexp"
"strings"
"testing"

"github.com/vmware/go-vcloud-director/v3/govcd"
Expand Down Expand Up @@ -36,6 +37,10 @@ func TestAccDataSourceNotFound(t *testing.T) {
func testSpecificDataSourceNotFound(dataSourceName string, vcdClient *VCDClient) func(*testing.T) {
return func(t *testing.T) {

if !vcdClient.Client.IsTm() && strings.HasPrefix(dataSourceName, "vcd_tm") {
t.Skipf("Skipping %s datasource not found test on VCD", dataSourceName)
}

type skipAlways struct {
dataSourceName string
reason string
Expand Down
70 changes: 31 additions & 39 deletions vcd/datasource_vcd_nsxt_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,58 @@ package vcd

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/go-vcloud-director/v3/govcd"
"github.com/vmware/go-vcloud-director/v3/types/v56"
)

// TODO: TM: validate compatibility with old data source

func datasourceVcdNsxtManager() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdNsxtManagerRead,

ReadContext: datasourceNsxtManagerRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Name of %s", labelNsxtManager),
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Description of %s", labelNsxtManager),
},
"username": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Username for authenticating to %s", labelNsxtManager),
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("URL of %s", labelNsxtManager),
},
"network_provider_scope": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Network Provider Scope for %s", labelNsxtManager),
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Status of %s", labelNsxtManager),
Description: "Name of NSX-T manager.",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("HREF of %s", labelNsxtManager),
Description: "HREF of NSX-T manager.",
},
},
}
}

func datasourceVcdNsxtManagerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func datasourceNsxtManagerRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)
c := crudConfig[*govcd.NsxtManagerOpenApi, types.NsxtManagerOpenApi]{
entityLabel: labelNsxtManager,
getEntityFunc: vcdClient.GetNsxtManagerOpenApiByName,
stateStoreFunc: setNsxtManagerData,
nsxtManagerName := d.Get("name").(string)

nsxtManagers, err := vcdClient.QueryNsxtManagerByName(nsxtManagerName)
if err != nil {
return diag.Errorf("could not find NSX-T manager by name '%s': %s", nsxtManagerName, err)
}
return readDatasource(ctx, d, meta, c)

if len(nsxtManagers) == 0 {
return diag.Errorf("%s found %d NSX-T managers with name '%s'",
govcd.ErrorEntityNotFound, len(nsxtManagers), nsxtManagerName)
}

if len(nsxtManagers) > 1 {
return diag.Errorf("found %d NSX-T managers with name '%s'", len(nsxtManagers), nsxtManagerName)
}

// We try to keep IDs clean
id := extractUuid(nsxtManagers[0].HREF)
urn, err := govcd.BuildUrnWithUuid("urn:vcloud:nsxtmanager:", id)
if err != nil {
return diag.Errorf("could not construct URN from id '%s': %s", id, err)
}
dSet(d, "name", nsxtManagers[0].Name)
dSet(d, "href", nsxtManagers[0].HREF)
d.SetId(urn)

return nil
}
65 changes: 65 additions & 0 deletions vcd/datasource_vcd_tm_nsxt_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package vcd

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/go-vcloud-director/v3/govcd"
"github.com/vmware/go-vcloud-director/v3/types/v56"
)

func datasourceVcdTmNsxtManager() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdNsxtManagerRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Name of %s", labelNsxtManager),
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Description of %s", labelNsxtManager),
},
"username": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Username for authenticating to %s", labelNsxtManager),
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("URL of %s", labelNsxtManager),
},
"network_provider_scope": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Network Provider Scope for %s", labelNsxtManager),
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Status of %s", labelNsxtManager),
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("HREF of %s", labelNsxtManager),
},
},
}
}

func datasourceVcdNsxtManagerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)
c := crudConfig[*govcd.NsxtManagerOpenApi, types.NsxtManagerOpenApi]{
entityLabel: labelNsxtManager,
getEntityFunc: vcdClient.GetNsxtManagerOpenApiByName,
stateStoreFunc: setNsxtManagerData,
}
return readDatasource(ctx, d, meta, c)
}
101 changes: 101 additions & 0 deletions vcd/datasource_vcd_tm_vcenter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package vcd

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/go-vcloud-director/v3/govcd"
"github.com/vmware/go-vcloud-director/v3/types/v56"
)

func datasourceVcdTmVcenter() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdVcenterRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Name of %s", labelTmVirtualCenter),
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("URL of %s", labelTmVirtualCenter),
},
"username": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Username of %s", labelTmVirtualCenter),
},
"is_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("Should the %s be enabled", labelTmVirtualCenter),
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Description of %s", labelTmVirtualCenter),
},
"has_proxy": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("A flag that shows if %s has proxy defined", labelTmVirtualCenter),
},
"is_connected": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("A flag that shows if %s is connected", labelTmVirtualCenter),
},
"mode": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Mode of %s", labelTmVirtualCenter),
},
"connection_status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Listener state of %s", labelTmVirtualCenter),
},
"cluster_health_status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Mode of %s", labelTmVirtualCenter),
},
"vcenter_version": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Version of %s", labelTmVirtualCenter),
},
"uuid": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("%s UUID", labelTmVirtualCenter),
},
"vcenter_host": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("%s hostname", labelTmVirtualCenter),
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "vCenter status",
},
},
}
}

func datasourceVcdVcenterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)

c := crudConfig[*govcd.VCenter, types.VSphereVirtualCenter]{
entityLabel: labelTmVirtualCenter,
getEntityFunc: vcdClient.GetVCenterByName,
stateStoreFunc: setTmVcenterData,
}
return readDatasource(ctx, d, meta, c)
}
Loading