-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support bridge confguration on segment
Add policy_bridge_profile data source and bridge_config clause on segments. Signed-off-by: Anna Khmelnitsky <akhmelnitsky@vmware.com>
- Loading branch information
Showing
9 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* Copyright © 2022 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceNsxtPolicyBridgeProfile() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceNsxtPolicyBridgeProfileRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"id": getDataSourceIDSchema(), | ||
"display_name": getDataSourceExtendedDisplayNameSchema(), | ||
"description": getDataSourceDescriptionSchema(), | ||
"path": getPathSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNsxtPolicyBridgeProfileRead(d *schema.ResourceData, m interface{}) error { | ||
connector := getPolicyConnector(m) | ||
|
||
_, err := policyDataSourceResourceRead(d, connector, isPolicyGlobalManager(m), "L2BridgeEndpointProfile", nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* Copyright © 2022 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
ep "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" | ||
) | ||
|
||
func TestAccDataSourceNsxtPolicyBridgeProfile_basic(t *testing.T) { | ||
name := getAccTestDataSourceName() | ||
testResourceName := "data.nsxt_policy_bridge_profile.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccNSXVersion(t, "3.0.0") }, | ||
Providers: testAccProviders, | ||
CheckDestroy: func(state *terraform.State) error { | ||
return testAccDataSourceNsxtPolicyBridgeProfileDeleteByName(name) | ||
}, | ||
Steps: []resource.TestStep{ | ||
{ | ||
PreConfig: func() { | ||
if err := testAccDataSourceNsxtPolicyBridgeProfileCreate(name); err != nil { | ||
panic(err) | ||
} | ||
}, | ||
Config: testAccNsxtPolicyBridgeProfileReadTemplate(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(testResourceName, "display_name", name), | ||
resource.TestCheckResourceAttr(testResourceName, "description", name), | ||
resource.TestCheckResourceAttrSet(testResourceName, "path"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceNsxtPolicyBridgeProfileCreate(name string) error { | ||
connector, err := testAccGetPolicyConnector() | ||
if err != nil { | ||
return fmt.Errorf("Error during test client initialization: %v", err) | ||
} | ||
|
||
displayName := name | ||
description := name | ||
obj := model.L2BridgeEndpointProfile{ | ||
Description: &description, | ||
DisplayName: &displayName, | ||
} | ||
|
||
// Generate a random ID for the resource | ||
uuid, _ := uuid.NewRandom() | ||
id := uuid.String() | ||
|
||
client := ep.NewEdgeBridgeProfilesClient(connector) | ||
err = client.Patch(defaultSite, defaultEnforcementPoint, id, obj) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error during Bridge Profile creation: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func testAccDataSourceNsxtPolicyBridgeProfileDeleteByName(name string) error { | ||
connector, err := testAccGetPolicyConnector() | ||
if err != nil { | ||
return fmt.Errorf("Error during test client initialization: %v", err) | ||
} | ||
|
||
// Find the object by name | ||
objID, err := testGetObjIDByName(name, "L2BridgeEndpointProfile") | ||
if err != nil { | ||
return nil | ||
} | ||
client := ep.NewEdgeBridgeProfilesClient(connector) | ||
err = client.Delete(defaultSite, defaultEnforcementPoint, objID) | ||
if err != nil { | ||
return fmt.Errorf("Error during Bridge Profile deletion: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func testAccNsxtPolicyBridgeProfileReadTemplate(name string) string { | ||
return fmt.Sprintf(` | ||
data "nsxt_policy_bridge_profile" "test" { | ||
display_name = "%s" | ||
}`, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.