@@ -5,12 +5,15 @@ package nsxt
5
5
6
6
import (
7
7
"fmt"
8
+ "github.com/vmware/vsphere-automation-sdk-go/lib/vapi/std/errors"
9
+ "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx"
8
10
"testing"
9
11
10
12
"github.com/google/uuid"
11
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12
14
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
13
15
ep "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points"
16
+ "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points/edge_clusters"
14
17
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
15
18
)
16
19
@@ -42,6 +45,39 @@ func TestAccDataSourceNsxtPolicyBridgeProfile_basic(t *testing.T) {
42
45
})
43
46
}
44
47
48
+ func getEdgeClusterPath () (string , error ) {
49
+ connector , err := testAccGetPolicyConnector ()
50
+ if err != nil {
51
+ return "" , fmt .Errorf ("error during test client initialization: %v" , err )
52
+ }
53
+ client := nsx .NewEdgeClustersClient (connector )
54
+ clusterList , err := client .List (nil , nil , nil , nil , nil )
55
+ if err != nil {
56
+ return "" , fmt .Errorf ("error during edge cluster list retrieval: %v" , err )
57
+ }
58
+ clusterName := getEdgeClusterName ()
59
+ clusterID := ""
60
+ if clusterList .Results != nil {
61
+ for _ , objList := range clusterList .Results {
62
+ if * objList .DisplayName == clusterName {
63
+ clusterID = * objList .Id
64
+ break
65
+ }
66
+ }
67
+ }
68
+ if clusterID != "" {
69
+ enClient := edge_clusters .NewEdgeNodesClient (connector )
70
+ objList , err := enClient .List (defaultSite , defaultEnforcementPoint , clusterID , nil , nil , nil , nil , nil , nil )
71
+ if err != nil {
72
+ return "" , fmt .Errorf ("error during edge node list retrieval: %v" , err )
73
+ }
74
+ if len (objList .Results ) > 0 {
75
+ return * objList .Results [0 ].Path , nil
76
+ }
77
+ }
78
+ return "" , errors.NotFound {}
79
+ }
80
+
45
81
func testAccDataSourceNsxtPolicyBridgeProfileCreate (name string ) error {
46
82
connector , err := testAccGetPolicyConnector ()
47
83
if err != nil {
@@ -59,6 +95,13 @@ func testAccDataSourceNsxtPolicyBridgeProfileCreate(name string) error {
59
95
uuid , _ := uuid .NewRandom ()
60
96
id := uuid .String ()
61
97
98
+ // Get Edge path
99
+ edgePath , err := getEdgeClusterPath ()
100
+ if err == nil {
101
+ obj .EdgePaths = []string {edgePath }
102
+ } else if ! isNotFoundError (err ) {
103
+ return err
104
+ }
62
105
client := ep .NewEdgeBridgeProfilesClient (connector )
63
106
err = client .Patch (defaultSite , defaultEnforcementPoint , id , obj )
64
107
0 commit comments