From 69b91c2928bc953df777ff23bfa380d05d4cc7b8 Mon Sep 17 00:00:00 2001 From: Shizhao Liu Date: Thu, 6 Apr 2023 00:29:16 +0000 Subject: [PATCH] API Refactoring for VPN resources NSX API that uses locale service path of VPN resources will be deprecated, this PR adds support for the new API that uses gateway path. The change in this PR includes: (1) Support for configuring VPN Resource with gateway path. (2) change data_source_nsxt_policy_ipsec_vpn_local_endpoint to use regex-based search API. (3) For VPN Sessions, if only specify the direction of Tcp Mss Clampling, the provider will use the auto-assigned value for the Maximum Segment Size. Signed-off-by: Shizhao Liu --- ...ce_nsxt_policy_ipsec_vpn_local_endpoint.go | 44 +- .../resource_nsxt_policy_ipsec_vpn_service.go | 119 ++++- ...urce_nsxt_policy_ipsec_vpn_service_test.go | 131 ++++- .../resource_nsxt_policy_ipsec_vpn_session.go | 23 +- nsxt/resource_nsxt_policy_l2_vpn_service.go | 101 +++- ...esource_nsxt_policy_l2_vpn_service_test.go | 153 +++++- nsxt/resource_nsxt_policy_l2_vpn_session.go | 128 +++-- ...esource_nsxt_policy_l2_vpn_session_test.go | 41 +- .../L2vpnServicesPackageTypes.go | 11 + .../tier_0s/l2vpn_services/SessionsClient.go | 335 +++++++++++++ .../tier_0s/l2vpn_services/SessionsTypes.go | 447 ++++++++++++++++++ .../L2vpnServicesPackageTypes.go | 11 + .../tier_1s/l2vpn_services/SessionsClient.go | 335 +++++++++++++ .../tier_1s/l2vpn_services/SessionsTypes.go | 447 ++++++++++++++++++ vendor/modules.txt | 2 + .../r/policy_ipsec_vpn_service.html.markdown | 3 +- .../r/policy_ipsec_vpn_session.html.markdown | 4 +- .../r/policy_l2_vpn_service.html.markdown | 3 +- .../r/policy_l2_vpn_session.html.markdown | 6 +- 19 files changed, 2166 insertions(+), 178 deletions(-) create mode 100644 vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/L2vpnServicesPackageTypes.go create mode 100644 vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsClient.go create mode 100644 vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsTypes.go create mode 100644 vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/L2vpnServicesPackageTypes.go create mode 100644 vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsClient.go create mode 100644 vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsTypes.go diff --git a/nsxt/data_source_nsxt_policy_ipsec_vpn_local_endpoint.go b/nsxt/data_source_nsxt_policy_ipsec_vpn_local_endpoint.go index 014f0e12f..e7ed4f2da 100644 --- a/nsxt/data_source_nsxt_policy_ipsec_vpn_local_endpoint.go +++ b/nsxt/data_source_nsxt_policy_ipsec_vpn_local_endpoint.go @@ -5,6 +5,7 @@ package nsxt import ( "fmt" + "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" @@ -36,42 +37,17 @@ func dataSourceNsxtPolicyIPSecVpnLocalEndpointRead(d *schema.ResourceData, m int servicePath := d.Get("service_path").(string) query := make(map[string]string) if len(servicePath) > 0 { - // In newer NSX versions, NSX removes locale service from the parent path when search API is concerned - objID := d.Get("id").(string) - objName := d.Get("display_name").(string) - client, err := newLocalEndpointClient(servicePath) - if err != nil { - return err + s := strings.Split(servicePath, "/") + if len(s) != 8 && len(s) != 6 { + // The policy path of IPSec VPN Service should be like /infra/tier-0s/aaa/locale-services/bbb/ipsec-vpn-services/ccc + // or /infra/tier-0s/aaa/ipsec-vpn-services/bbb + return fmt.Errorf("Invalid IPSec Vpn Service path: %s", servicePath) } - if objID != "" { - obj, err := client.Get(connector, objID) - if err != nil { - return fmt.Errorf("Failed to locate Local Endpoint %s/%s: %v", servicePath, objID, err) - } - d.SetId(*obj.Id) - d.Set("display_name", obj.DisplayName) - d.Set("description", obj.Description) - d.Set("path", obj.Path) - d.Set("local_address", obj.LocalAddress) - return nil + if len(s) == 8 { + // search API does not recognized the locale-services part in the VPN service path + servicePath = strings.Join(append(s[:4], s[6:]...), "/") } - - objList, err := client.List(connector) - if err != nil { - return fmt.Errorf("Failed to list local endpoints: %v", err) - } - - for _, obj := range objList { - if *obj.DisplayName == objName { - d.SetId(*obj.Id) - d.Set("display_name", obj.DisplayName) - d.Set("description", obj.Description) - d.Set("path", obj.Path) - d.Set("local_address", obj.LocalAddress) - return nil - } - } - return fmt.Errorf("Failed to locate Local Endpoint under %s named %s", servicePath, objName) + query["parent_path"] = fmt.Sprintf("%s*", servicePath) } objInt, err := policyDataSourceResourceReadWithValidation(d, connector, isPolicyGlobalManager(m), "IPSecVpnLocalEndpoint", query, false) if err != nil { diff --git a/nsxt/resource_nsxt_policy_ipsec_vpn_service.go b/nsxt/resource_nsxt_policy_ipsec_vpn_service.go index 10b45620b..c7e5cc77f 100644 --- a/nsxt/resource_nsxt_policy_ipsec_vpn_service.go +++ b/nsxt/resource_nsxt_policy_ipsec_vpn_service.go @@ -11,7 +11,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s" t0_locale_service "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s" t1_locale_service "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" ) @@ -35,13 +37,21 @@ func resourceNsxtPolicyIPSecVpnService() *schema.Resource { }, Schema: map[string]*schema.Schema{ - "nsx_id": getNsxIDSchema(), - "path": getPathSchema(), - "display_name": getDisplayNameSchema(), - "description": getDescriptionSchema(), - "revision": getRevisionSchema(), - "tag": getTagsSchema(), - "locale_service_path": getPolicyPathSchema(true, false, "Polciy path for the locale service."), + "nsx_id": getNsxIDSchema(), + "path": getPathSchema(), + "display_name": getDisplayNameSchema(), + "description": getDescriptionSchema(), + "revision": getRevisionSchema(), + "tag": getTagsSchema(), + "gateway_path": getPolicyPathSchema(false, true, "Policy path for the gateway."), + "locale_service_path": { + Type: schema.TypeString, + Description: "Polciy path for the locale service.", + Optional: true, + ForceNew: false, + Deprecated: "Use gateway_path instead.", + ValidateFunc: validatePolicyPath(), + }, "enabled": { Type: schema.TypeBool, Description: "Enable/Disable IPSec VPN service.", @@ -67,6 +77,14 @@ func resourceNsxtPolicyIPSecVpnService() *schema.Resource { } func getNsxtPolicyIPSecVpnServiceByID(connector client.Connector, gwID string, isT0 bool, localeServiceID string, serviceID string, isGlobalManager bool) (model.IPSecVpnService, error) { + if localeServiceID == "" { + if isT0 { + client := tier_0s.NewIpsecVpnServicesClient(connector) + return client.Get(gwID, serviceID) + } + client := tier_1s.NewIpsecVpnServicesClient(connector) + return client.Get(gwID, serviceID) + } if isT0 { client := t0_locale_service.NewIpsecVpnServicesClient(connector) return client.Get(gwID, localeServiceID, serviceID) @@ -77,6 +95,14 @@ func getNsxtPolicyIPSecVpnServiceByID(connector client.Connector, gwID string, i func patchNsxtPolicyIPSecVpnService(connector client.Connector, gwID string, localeServiceID string, ipSecVpnService model.IPSecVpnService, isT0 bool) error { id := *ipSecVpnService.Id + if localeServiceID == "" { + if isT0 { + client := tier_0s.NewIpsecVpnServicesClient(connector) + return client.Patch(gwID, id, ipSecVpnService) + } + client := tier_1s.NewIpsecVpnServicesClient(connector) + return client.Patch(gwID, id, ipSecVpnService) + } if isT0 { client := t0_locale_service.NewIpsecVpnServicesClient(connector) return client.Patch(gwID, localeServiceID, id, ipSecVpnService) @@ -87,6 +113,16 @@ func patchNsxtPolicyIPSecVpnService(connector client.Connector, gwID string, loc func updateNsxtPolicyIPSecVpnService(connector client.Connector, gwID string, localeServiceID string, ipSecVpnService model.IPSecVpnService, isT0 bool) error { id := *ipSecVpnService.Id + if localeServiceID == "" { + if isT0 { + client := tier_0s.NewIpsecVpnServicesClient(connector) + _, err := client.Update(gwID, id, ipSecVpnService) + return err + } + client := tier_1s.NewIpsecVpnServicesClient(connector) + _, err := client.Update(gwID, id, ipSecVpnService) + return err + } if isT0 { client := t0_locale_service.NewIpsecVpnServicesClient(connector) _, err := client.Update(gwID, localeServiceID, id, ipSecVpnService) @@ -102,19 +138,33 @@ func resourceNsxtPolicyIPSecVpnServiceImport(d *schema.ResourceData, m interface s := strings.Split(importID, "/") err := fmt.Errorf("Expected policy path for the IPSec VPN Service, got %s", importID) // The policy path of IPSec VPN Service should be like /infra/tier-0s/aaa/locale-services/bbb/ipsec-vpn-services/ccc - if len(s) != 8 { + // or /infra/tier-0s/aaa/ipsec-vpn-services/bbb + if len(s) != 8 && len(s) != 6 { return nil, err } - d.SetId(s[7]) + useLocaleService := len(s) == 8 + d.SetId(s[len(s)-1]) s = strings.Split(importID, "/ipsec-vpn-services/") if len(s) != 2 { return []*schema.ResourceData{d}, err } - d.Set("locale_service_path", s[0]) + if useLocaleService { + d.Set("locale_service_path", s[0]) + } else { + d.Set("gateway_path", s[0]) + } return []*schema.ResourceData{d}, nil } func deleteNsxtPolicyIPSecVpnService(connector client.Connector, gwID string, localeServiceID string, isT0 bool, id string) error { + if localeServiceID == "" { + if isT0 { + client := tier_0s.NewIpsecVpnServicesClient(connector) + return client.Delete(gwID, id) + } + client := tier_1s.NewIpsecVpnServicesClient(connector) + return client.Delete(gwID, id) + } if isT0 { client := t0_locale_service.NewIpsecVpnServicesClient(connector) return client.Delete(gwID, localeServiceID, id) @@ -196,6 +246,15 @@ func getIPSecVPNBypassRulesFromSchema(d *schema.ResourceData) []model.IPSecVpnRu return nil } +func getLocaleServiceAndGatewayPath(d *schema.ResourceData) (string, string, error) { + gatewayPath := d.Get("gateway_path").(string) + localeServicePath := d.Get("locale_service_path").(string) + if gatewayPath == "" && localeServicePath == "" { + return "", "", fmt.Errorf("At least one of gateway path and locale service path should be provided for VPN resources") + } + return gatewayPath, localeServicePath, nil +} + func resourceNsxtPolicyIPSecVpnServiceRead(d *schema.ResourceData, m interface{}) error { connector := getPolicyConnector(m) @@ -203,11 +262,17 @@ func resourceNsxtPolicyIPSecVpnServiceRead(d *schema.ResourceData, m interface{} if id == "" { return fmt.Errorf("Error obtaining IPSecVpnService ID") } - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } obj, err := getNsxtPolicyIPSecVpnServiceByID(connector, gwID, isT0, localeServiceID, id, isPolicyGlobalManager(m)) if err != nil { return handleReadError(d, "IPSecVpnService", id, err) @@ -229,11 +294,17 @@ func resourceNsxtPolicyIPSecVpnServiceRead(d *schema.ResourceData, m interface{} func resourceNsxtPolicyIPSecVpnServiceCreate(d *schema.ResourceData, m interface{}) error { connector := getPolicyConnector(m) - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } isGlobalManager := isPolicyGlobalManager(m) id := d.Get("nsx_id").(string) if id == "" { @@ -285,11 +356,17 @@ func resourceNsxtPolicyIPSecVpnServiceUpdate(d *schema.ResourceData, m interface if id == "" { return fmt.Errorf("Error obtaining IPSec VPN Service ID") } - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } displayName := d.Get("display_name").(string) description := d.Get("description").(string) @@ -329,11 +406,17 @@ func resourceNsxtPolicyIPSecVpnServiceDelete(d *schema.ResourceData, m interface return fmt.Errorf("Error obtaining IPSec VPN Service ID") } - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } err = deleteNsxtPolicyIPSecVpnService(getPolicyConnector(m), gwID, localeServiceID, isT0, id) if err != nil { diff --git a/nsxt/resource_nsxt_policy_ipsec_vpn_service_test.go b/nsxt/resource_nsxt_policy_ipsec_vpn_service_test.go index 320230eac..3c3ebe21a 100644 --- a/nsxt/resource_nsxt_policy_ipsec_vpn_service_test.go +++ b/nsxt/resource_nsxt_policy_ipsec_vpn_service_test.go @@ -44,7 +44,7 @@ func TestAccResourceNsxtPolicyIPSecVpnService_basic(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyIPSecVpnServiceTemplate(true), + Config: testAccNsxtPolicyIPSecVpnServiceTemplate(true, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyIPSecVpnServiceExists(accTestPolicyIPSecVpnServiceCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyIPSecVpnServiceCreateAttributes["display_name"]), @@ -64,7 +64,7 @@ func TestAccResourceNsxtPolicyIPSecVpnService_basic(t *testing.T) { ), }, { - Config: testAccNsxtPolicyIPSecVpnServiceTemplate(false), + Config: testAccNsxtPolicyIPSecVpnServiceTemplate(false, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyIPSecVpnServiceExists(accTestPolicyIPSecVpnServiceUpdateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyIPSecVpnServiceUpdateAttributes["display_name"]), @@ -84,7 +84,7 @@ func TestAccResourceNsxtPolicyIPSecVpnService_basic(t *testing.T) { ), }, { - Config: testAccNsxtPolicyIPSecVpnServiceMinimalistic(), + Config: testAccNsxtPolicyIPSecVpnServiceMinimalistic(false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyIPSecVpnServiceExists(accTestPolicyIPSecVpnServiceCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "description", ""), @@ -103,6 +103,73 @@ func TestAccResourceNsxtPolicyIPSecVpnService_basic(t *testing.T) { }) } +func TestAccResourceNsxtPolicyIPSecVpnService_withGateway(t *testing.T) { + testResourceName := "nsxt_policy_ipsec_vpn_service.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t) }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtPolicyIPSecVpnServiceCheckDestroy(state, accTestPolicyIPSecVpnServiceUpdateAttributes["display_name"]) + }, + Steps: []resource.TestStep{ + { + Config: testAccNsxtPolicyIPSecVpnServiceTemplate(true, true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyIPSecVpnServiceExists(accTestPolicyIPSecVpnServiceCreateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyIPSecVpnServiceCreateAttributes["display_name"]), + resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyIPSecVpnServiceCreateAttributes["description"]), + resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"), + resource.TestCheckResourceAttr(testResourceName, "enabled", accTestPolicyIPSecVpnServiceCreateAttributes["enabled"]), + resource.TestCheckResourceAttr(testResourceName, "ha_sync", accTestPolicyIPSecVpnServiceCreateAttributes["ha_sync"]), + resource.TestCheckResourceAttr(testResourceName, "ike_log_level", accTestPolicyIPSecVpnServiceCreateAttributes["ike_log_level"]), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.0.sources.0", accTestPolicyIPSecVpnServiceCreateAttributes["sources"]), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.0.destinations.0", accTestPolicyIPSecVpnServiceCreateAttributes["destinations"]), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.0.action", accTestPolicyIPSecVpnServiceCreateAttributes["action"]), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + ), + }, + { + Config: testAccNsxtPolicyIPSecVpnServiceTemplate(false, true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyIPSecVpnServiceExists(accTestPolicyIPSecVpnServiceUpdateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyIPSecVpnServiceUpdateAttributes["display_name"]), + resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyIPSecVpnServiceUpdateAttributes["description"]), + resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"), + resource.TestCheckResourceAttr(testResourceName, "enabled", accTestPolicyIPSecVpnServiceUpdateAttributes["enabled"]), + resource.TestCheckResourceAttr(testResourceName, "ha_sync", accTestPolicyIPSecVpnServiceUpdateAttributes["ha_sync"]), + resource.TestCheckResourceAttr(testResourceName, "ike_log_level", accTestPolicyIPSecVpnServiceUpdateAttributes["ike_log_level"]), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.0.sources.0", accTestPolicyIPSecVpnServiceUpdateAttributes["sources"]), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.0.destinations.0", accTestPolicyIPSecVpnServiceUpdateAttributes["destinations"]), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.0.action", accTestPolicyIPSecVpnServiceUpdateAttributes["action"]), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + ), + }, + { + Config: testAccNsxtPolicyIPSecVpnServiceMinimalistic(true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyIPSecVpnServiceExists(accTestPolicyIPSecVpnServiceCreateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "description", ""), + resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"), + resource.TestCheckResourceAttr(testResourceName, "bypass_rule.#", "0"), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), + ), + }, + }, + }) +} + func TestAccResourceNsxtPolicyIPSecVpnService_Import(t *testing.T) { resourceName := "nsxt_policy_ipsec_vpn_service.test" @@ -114,7 +181,7 @@ func TestAccResourceNsxtPolicyIPSecVpnService_Import(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyIPSecVpnServiceTemplate(true), + Config: testAccNsxtPolicyIPSecVpnServiceTemplate(true, false), }, { ResourceName: resourceName, @@ -137,7 +204,14 @@ func testAccNsxtPolicyIPSecVpnServiceImporterGetID(s *terraform.State) (string, return "", fmt.Errorf("Policy IPSecVpnService resource ID not set in resources") } localeServicePath := rs.Primary.Attributes["locale_service_path"] - return fmt.Sprintf("%s/ipsec-vpn-services/%s", localeServicePath, resourceID), nil + gatewayPath := rs.Primary.Attributes["gateway_path"] + if gatewayPath == "" && localeServicePath == "" { + return "", fmt.Errorf("At least one of gateway path and locale service path should be provided for VPN resources") + } + if localeServicePath != "" { + return fmt.Sprintf("%s/ipsec-vpn-services/%s", localeServicePath, resourceID), nil + } + return fmt.Sprintf("%s/ipsec-vpn-services/%s", gatewayPath, resourceID), nil } func testAccNsxtPolicyIPSecVpnServiceExists(displayName string, resourceName string) resource.TestCheckFunc { @@ -156,10 +230,16 @@ func testAccNsxtPolicyIPSecVpnServiceExists(displayName string, resourceName str } localeServicePath := rs.Primary.Attributes["locale_service_path"] + gatewayPath := rs.Primary.Attributes["gateway_path"] + if gatewayPath == "" && localeServicePath == "" { + return fmt.Errorf("At least one of gateway path and locale service path should be provided for VPN resources") + } isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) - - if err != nil { - return nil + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } + if err != nil && gatewayPath == "" { + return fmt.Errorf("Invalid locale service path %s", localeServicePath) } _, err1 := getNsxtPolicyIPSecVpnServiceByID(connector, gwID, isT0, localeServiceID, resourceID, testAccIsGlobalManager()) if err1 != nil { @@ -180,9 +260,12 @@ func testAccNsxtPolicyIPSecVpnServiceCheckDestroy(state *terraform.State, displa resourceID := rs.Primary.Attributes["id"] localeServicePath := rs.Primary.Attributes["locale_service_path"] + gatewayPath := rs.Primary.Attributes["gateway_path"] isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) - - if err != nil { + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } + if err != nil && gatewayPath == "" { return nil } @@ -194,18 +277,19 @@ func testAccNsxtPolicyIPSecVpnServiceCheckDestroy(state *terraform.State, displa return nil } -func testAccNsxtPolicyIPSecVpnServiceTemplate(createFlow bool) string { +func testAccNsxtPolicyIPSecVpnServiceTemplate(createFlow bool, useGatewayPath bool) string { var attrMap map[string]string if createFlow { attrMap = accTestPolicyIPSecVpnServiceCreateAttributes } else { attrMap = accTestPolicyIPSecVpnServiceUpdateAttributes } + gatewayOrLocaleServicePath := getGatewayOrLocaleServicePath(useGatewayPath, true) return testAccNsxtPolicyTier0WithEdgeClusterForVPN() + fmt.Sprintf(` resource "nsxt_policy_ipsec_vpn_service" "test" { display_name = "%s" description = "%s" - locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path + %s enabled = "%s" ha_sync = "%s" ike_log_level = "%s" @@ -219,13 +303,28 @@ resource "nsxt_policy_ipsec_vpn_service" "test" { scope = "scope1" tag = "tag1" } - }`, attrMap["display_name"], attrMap["description"], attrMap["enabled"], attrMap["ha_sync"], attrMap["ike_log_level"], attrMap["sources"], attrMap["destinations"], attrMap["action"]) + }`, attrMap["display_name"], attrMap["description"], gatewayOrLocaleServicePath, attrMap["enabled"], attrMap["ha_sync"], attrMap["ike_log_level"], attrMap["sources"], attrMap["destinations"], attrMap["action"]) +} + +func getGatewayOrLocaleServicePath(useGatewayPath bool, isT0 bool) string { + if useGatewayPath { + if isT0 { + return "gateway_path = nsxt_policy_tier0_gateway.test.path" + } + return "gateway_path = nsxt_policy_tier1_gateway.test.path" + } + if isT0 { + return "locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path" + } + return "locale_service_path = one(nsxt_policy_tier1_gateway.test.locale_service).path" + } -func testAccNsxtPolicyIPSecVpnServiceMinimalistic() string { +func testAccNsxtPolicyIPSecVpnServiceMinimalistic(useGatewayPath bool) string { + gatewayOrLocaleServicePath := getGatewayOrLocaleServicePath(useGatewayPath, true) return testAccNsxtPolicyTier0WithEdgeClusterForVPN() + fmt.Sprintf(` resource "nsxt_policy_ipsec_vpn_service" "test" { display_name = "%s" - locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path - }`, accTestPolicyIPSecVpnServiceUpdateAttributes["display_name"]) + %s + }`, accTestPolicyIPSecVpnServiceUpdateAttributes["display_name"], gatewayOrLocaleServicePath) } diff --git a/nsxt/resource_nsxt_policy_ipsec_vpn_session.go b/nsxt/resource_nsxt_policy_ipsec_vpn_session.go index 7842e4b5d..72607e488 100644 --- a/nsxt/resource_nsxt_policy_ipsec_vpn_session.go +++ b/nsxt/resource_nsxt_policy_ipsec_vpn_session.go @@ -157,10 +157,10 @@ func resourceNsxtPolicyIPSecVpnSession() *schema.Resource { ValidateFunc: validation.StringInSlice(TCPMssClampingDirections, false), }, "max_segment_size": { - Type: schema.TypeInt, - Description: "Maximum amount of data the host will accept in a Tcp segment.", - Optional: true, - ValidateFunc: validation.IntBetween(108, 8860), + Type: schema.TypeInt, + Description: "Maximum amount of data the host will accept in a Tcp segment.", + Optional: true, + Computed: true, }, }, } @@ -226,8 +226,10 @@ func getIPSecVPNSessionFromSchema(d *schema.ResourceData) (*data.StructValue, er if nsxVersionHigherOrEqual("3.2.0") { if direction != "" { tcpMSSClamping := model.TcpMaximumSegmentSizeClamping{ - Direction: &direction, - MaxSegmentSize: &mss, + Direction: &direction, + } + if mss > 0 { + tcpMSSClamping.MaxSegmentSize = &mss } routeObj.TcpMssClamping = &tcpMSSClamping } @@ -272,8 +274,10 @@ func getIPSecVPNSessionFromSchema(d *schema.ResourceData) (*data.StructValue, er if nsxVersionHigherOrEqual("3.2.0") { if direction != "" { tcpMSSClamping := model.TcpMaximumSegmentSizeClamping{ - Direction: &direction, - MaxSegmentSize: &mss, + Direction: &direction, + } + if mss > 0 { + tcpMSSClamping.MaxSegmentSize = &mss } policyObj.TcpMssClamping = &tcpMSSClamping } @@ -418,7 +422,7 @@ func (c *ipsecSessionClient) Delete(connector client.Connector, id string) error func parseIPSecVPNServicePolicyPath(path string) (bool, string, string, string, error) { segs := strings.Split(path, "/") // Path should be like /infra/tier-1s/aaa/locale-services/default/ipsec-vpn-services/ccc - // or /infra/tier-0s/vmc/ipsec-vpn-services/default for VMC + // or /infra/tier-0s/aaa/ipsec-vpn-services/bbb segCount := len(segs) if segCount < 6 || segCount > 8 || (segs[segCount-2] != "ipsec-vpn-services") { // error - this is not a segment path @@ -430,7 +434,6 @@ func parseIPSecVPNServicePolicyPath(path string) (bool, string, string, string, localeServiceID := "" if segCount == 8 { - // not VMC localeServiceID = segs[5] } diff --git a/nsxt/resource_nsxt_policy_l2_vpn_service.go b/nsxt/resource_nsxt_policy_l2_vpn_service.go index 3e4107469..414242841 100644 --- a/nsxt/resource_nsxt_policy_l2_vpn_service.go +++ b/nsxt/resource_nsxt_policy_l2_vpn_service.go @@ -11,7 +11,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s" t0_locale_service "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s" t1_locale_service "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" ) @@ -32,13 +34,21 @@ func resourceNsxtPolicyL2VpnService() *schema.Resource { }, Schema: map[string]*schema.Schema{ - "nsx_id": getNsxIDSchema(), - "path": getPathSchema(), - "display_name": getDisplayNameSchema(), - "description": getDescriptionSchema(), - "revision": getRevisionSchema(), - "tag": getTagsSchema(), - "locale_service_path": getPolicyPathSchema(true, false, "Policy path for the locale service."), + "nsx_id": getNsxIDSchema(), + "path": getPathSchema(), + "display_name": getDisplayNameSchema(), + "description": getDescriptionSchema(), + "revision": getRevisionSchema(), + "tag": getTagsSchema(), + "gateway_path": getPolicyPathSchema(false, true, "Policy path for the gateway."), + "locale_service_path": { + Type: schema.TypeString, + Description: "Polciy path for the locale service.", + Optional: true, + ForceNew: false, + Deprecated: "Use gateway_path instead.", + ValidateFunc: validatePolicyPath(), + }, "enable_hub": { Type: schema.TypeBool, Description: "This property applies only in SERVER mode. If set to true, traffic from any client will be replicated to all other clients. If set to false, traffic received from clients is only replicated to the local VPN endpoint.", @@ -66,6 +76,14 @@ func resourceNsxtPolicyL2VpnService() *schema.Resource { } func getNsxtPolicyL2VpnServiceByID(connector client.Connector, gwID string, isT0 bool, localeServiceID string, serviceID string, isGlobalManager bool) (model.L2VPNService, error) { + if localeServiceID == "" { + if isT0 { + client := tier_0s.NewL2vpnServicesClient(connector) + return client.Get(gwID, serviceID) + } + client := tier_1s.NewL2vpnServicesClient(connector) + return client.Get(gwID, serviceID) + } if isT0 { client := t0_locale_service.NewL2vpnServicesClient(connector) return client.Get(gwID, localeServiceID, serviceID) @@ -76,15 +94,32 @@ func getNsxtPolicyL2VpnServiceByID(connector client.Connector, gwID string, isT0 func patchNsxtPolicyL2VpnService(connector client.Connector, gwID string, localeServiceID string, l2VpnService model.L2VPNService, isT0 bool) error { id := *l2VpnService.Id + if localeServiceID == "" { + if isT0 { + client := tier_0s.NewL2vpnServicesClient(connector) + return client.Patch(gwID, id, l2VpnService) + } + client := tier_1s.NewL2vpnServicesClient(connector) + return client.Patch(gwID, id, l2VpnService) + } if isT0 { client := t0_locale_service.NewL2vpnServicesClient(connector) return client.Patch(gwID, localeServiceID, id, l2VpnService) } client := t1_locale_service.NewL2vpnServicesClient(connector) return client.Patch(gwID, localeServiceID, id, l2VpnService) + } func deleteNsxtPolicyL2VpnService(connector client.Connector, gwID string, localeServiceID string, isT0 bool, id string) error { + if localeServiceID == "" { + if isT0 { + client := tier_0s.NewL2vpnServicesClient(connector) + return client.Delete(gwID, id) + } + client := tier_1s.NewL2vpnServicesClient(connector) + return client.Delete(gwID, id) + } if isT0 { client := t0_locale_service.NewL2vpnServicesClient(connector) return client.Delete(gwID, localeServiceID, id) @@ -98,15 +133,21 @@ func resourceNsxtPolicyL2VpnServiceImport(d *schema.ResourceData, m interface{}) s := strings.Split(importID, "/") err := fmt.Errorf("Expected policy path for the L2 VPN Service, got %s", importID) // The policy path of L2 VPN Service should be like /infra/tier-0s/aaa/locale-services/bbb/l2vpn-services/ccc - if len(s) != 8 { + // or /infra/tier-0s/aaa/l2vpn-services/bbb + if len(s) != 8 && len(s) != 6 { return nil, err } - d.SetId(s[7]) + useLocaleService := (len(s) == 8) + d.SetId(s[len(s)-1]) s = strings.Split(importID, "/l2vpn-services/") if len(s) != 2 { return []*schema.ResourceData{d}, err } - d.Set("locale_service_path", s[0]) + if useLocaleService { + d.Set("locale_service_path", s[0]) + } else { + d.Set("gateway_path", s[0]) + } return []*schema.ResourceData{d}, nil } @@ -117,11 +158,17 @@ func resourceNsxtPolicyL2VpnServiceRead(d *schema.ResourceData, m interface{}) e if id == "" { return fmt.Errorf("Error obtaining L2VpnService ID") } - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } obj, err := getNsxtPolicyL2VpnServiceByID(connector, gwID, isT0, localeServiceID, id, isPolicyGlobalManager(m)) if err != nil { return handleReadError(d, "L2VpnService", id, err) @@ -143,11 +190,17 @@ func resourceNsxtPolicyL2VpnServiceRead(d *schema.ResourceData, m interface{}) e func resourceNsxtPolicyL2VpnServiceCreate(d *schema.ResourceData, m interface{}) error { connector := getPolicyConnector(m) - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } isGlobalManager := isPolicyGlobalManager(m) id := d.Get("nsx_id").(string) if id == "" { @@ -201,11 +254,17 @@ func resourceNsxtPolicyL2VpnServiceUpdate(d *schema.ResourceData, m interface{}) if id == "" { return fmt.Errorf("Error obtaining L2 VPN Service ID") } - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } displayName := d.Get("display_name").(string) description := d.Get("description").(string) @@ -249,11 +308,17 @@ func resourceNsxtPolicyL2VpnServiceDelete(d *schema.ResourceData, m interface{}) return fmt.Errorf("Error obtaining L2 VPN Service ID") } - localeServicePath := d.Get("locale_service_path").(string) - isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + gatewayPath, localeServicePath, err := getLocaleServiceAndGatewayPath(d) if err != nil { + return nil + } + isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) + if err != nil && gatewayPath == "" { return err } + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } err = deleteNsxtPolicyL2VpnService(getPolicyConnector(m), gwID, localeServiceID, isT0, id) if err != nil { diff --git a/nsxt/resource_nsxt_policy_l2_vpn_service_test.go b/nsxt/resource_nsxt_policy_l2_vpn_service_test.go index 09e775b98..f1f8c0862 100644 --- a/nsxt/resource_nsxt_policy_l2_vpn_service_test.go +++ b/nsxt/resource_nsxt_policy_l2_vpn_service_test.go @@ -46,7 +46,7 @@ func TestAccResourceNsxtPolicyL2VpnService_basic(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyL2VpnServiceMinimalistic(), + Config: testAccNsxtPolicyL2VpnServiceMinimalistic(false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "description", ""), @@ -58,7 +58,7 @@ func TestAccResourceNsxtPolicyL2VpnService_basic(t *testing.T) { ), }, { - Config: testAccNsxtPolicyL2VpnServiceTemplate(true, false), + Config: testAccNsxtPolicyL2VpnServiceTemplate(true, false, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnServiceCreateAttributes["display_name"]), @@ -75,7 +75,7 @@ func TestAccResourceNsxtPolicyL2VpnService_basic(t *testing.T) { ), }, { - Config: testAccNsxtPolicyL2VpnServiceTemplate(false, false), + Config: testAccNsxtPolicyL2VpnServiceTemplate(false, false, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceUpdateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnServiceUpdateAttributes["display_name"]), @@ -98,6 +98,66 @@ func TestAccResourceNsxtPolicyL2VpnService_basic(t *testing.T) { }) } +func TestAccResourceNsxtPolicyL2VpnService_withGateway(t *testing.T) { + testResourceName := "nsxt_policy_l2_vpn_service.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t) }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtPolicyL2VpnServiceCheckDestroy(state, accTestPolicyL2VpnServiceUpdateAttributes["display_name"]) + }, + Steps: []resource.TestStep{ + { + Config: testAccNsxtPolicyL2VpnServiceMinimalistic(true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceCreateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "description", ""), + resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), + ), + }, + { + Config: testAccNsxtPolicyL2VpnServiceTemplate(true, false, true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceCreateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnServiceCreateAttributes["display_name"]), + resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyL2VpnServiceCreateAttributes["description"]), + resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"), + resource.TestCheckResourceAttr(testResourceName, "enable_hub", accTestPolicyL2VpnServiceCreateAttributes["enable_hub"]), + resource.TestCheckResourceAttr(testResourceName, "mode", accTestPolicyL2VpnServiceCreateAttributes["mode"]), + resource.TestCheckResourceAttr(testResourceName, "encap_ip_pool.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "encap_ip_pool.0", accTestPolicyL2VpnServiceCreateAttributes["encap_ip_pool"]), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + ), + }, + { + Config: testAccNsxtPolicyL2VpnServiceTemplate(false, false, true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceUpdateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnServiceUpdateAttributes["display_name"]), + resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyL2VpnServiceUpdateAttributes["description"]), + resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"), + resource.TestCheckResourceAttr(testResourceName, "enable_hub", accTestPolicyL2VpnServiceUpdateAttributes["enable_hub"]), + resource.TestCheckResourceAttr(testResourceName, "mode", accTestPolicyL2VpnServiceUpdateAttributes["mode"]), + resource.TestCheckResourceAttr(testResourceName, "encap_ip_pool.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "encap_ip_pool.0", accTestPolicyL2VpnServiceUpdateAttributes["encap_ip_pool"]), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + ), + }, + }, + }) +} + func TestAccResourceNsxtPolicyL2VpnService_ClientMode(t *testing.T) { testResourceName := "nsxt_policy_l2_vpn_service.test" @@ -109,7 +169,7 @@ func TestAccResourceNsxtPolicyL2VpnService_ClientMode(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyL2VpnServiceTemplate(false, true), + Config: testAccNsxtPolicyL2VpnServiceTemplate(false, true, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceCreateClientModeAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnServiceCreateClientModeAttributes["display_name"]), @@ -132,6 +192,37 @@ func TestAccResourceNsxtPolicyL2VpnService_ClientMode(t *testing.T) { }) } +func TestAccResourceNsxtPolicyL2VpnService_ClientMode_GatewayPath(t *testing.T) { + testResourceName := "nsxt_policy_l2_vpn_service.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t) }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtPolicyL2VpnServiceCheckDestroy(state, accTestPolicyL2VpnServiceCreateClientModeAttributes["display_name"]) + }, + Steps: []resource.TestStep{ + { + Config: testAccNsxtPolicyL2VpnServiceTemplate(false, true, true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyL2VpnServiceExists(accTestPolicyL2VpnServiceCreateClientModeAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnServiceCreateClientModeAttributes["display_name"]), + resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyL2VpnServiceCreateClientModeAttributes["description"]), + resource.TestCheckResourceAttrSet(testResourceName, "gateway_path"), + resource.TestCheckResourceAttr(testResourceName, "enable_hub", accTestPolicyL2VpnServiceCreateClientModeAttributes["enable_hub"]), + resource.TestCheckResourceAttr(testResourceName, "mode", accTestPolicyL2VpnServiceCreateClientModeAttributes["mode"]), + resource.TestCheckResourceAttr(testResourceName, "encap_ip_pool.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "encap_ip_pool.0", accTestPolicyL2VpnServiceCreateClientModeAttributes["encap_ip_pool"]), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + ), + }, + }, + }) +} + func TestAccResourceNsxtPolicyL2VpnService_Import(t *testing.T) { resourceName := "nsxt_policy_l2_vpn_service.test" @@ -143,7 +234,7 @@ func TestAccResourceNsxtPolicyL2VpnService_Import(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyL2VpnServiceTemplate(true, false), + Config: testAccNsxtPolicyL2VpnServiceTemplate(true, false, false), }, { ResourceName: resourceName, @@ -166,7 +257,14 @@ func testAccNsxtPolicyL2VpnServiceImporterGetID(s *terraform.State) (string, err return "", fmt.Errorf("Policy L2VpnService resource ID not set in resources") } localeServicePath := rs.Primary.Attributes["locale_service_path"] - return fmt.Sprintf("%s/l2vpn-services/%s", localeServicePath, resourceID), nil + gatewayPath := rs.Primary.Attributes["gateway_path"] + if gatewayPath == "" && localeServicePath == "" { + return "", fmt.Errorf("At least one of gateway path and locale service path should be provided for VPN resources") + } + if localeServicePath != "" { + return fmt.Sprintf("%s/l2vpn-services/%s", localeServicePath, resourceID), nil + } + return fmt.Sprintf("%s/l2vpn-services/%s", gatewayPath, resourceID), nil } func testAccNsxtPolicyL2VpnServiceExists(displayName string, resourceName string) resource.TestCheckFunc { @@ -185,10 +283,16 @@ func testAccNsxtPolicyL2VpnServiceExists(displayName string, resourceName string } localeServicePath := rs.Primary.Attributes["locale_service_path"] + gatewayPath := rs.Primary.Attributes["gateway_path"] + if gatewayPath == "" && localeServicePath == "" { + return fmt.Errorf("At least one of gateway path and locale service path should be provided for VPN resources") + } isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) - - if err != nil { - return nil + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } + if err != nil && gatewayPath == "" { + return fmt.Errorf("Invalid locale service path %s", localeServicePath) } _, err1 := getNsxtPolicyL2VpnServiceByID(connector, gwID, isT0, localeServiceID, resourceID, testAccIsGlobalManager()) if err1 != nil { @@ -209,9 +313,12 @@ func testAccNsxtPolicyL2VpnServiceCheckDestroy(state *terraform.State, displayNa resourceID := rs.Primary.Attributes["id"] localeServicePath := rs.Primary.Attributes["locale_service_path"] + gatewayPath := rs.Primary.Attributes["gateway_path"] isT0, gwID, localeServiceID, err := parseLocaleServicePolicyPath(localeServicePath) - - if err != nil { + if localeServiceID == "" { + isT0, gwID = parseGatewayPolicyPath(gatewayPath) + } + if err != nil && gatewayPath == "" { return nil } @@ -223,7 +330,7 @@ func testAccNsxtPolicyL2VpnServiceCheckDestroy(state *terraform.State, displayNa return nil } -func testAccNsxtPolicyL2VpnServiceTemplate(createFlow bool, clientMode bool) string { +func testAccNsxtPolicyL2VpnServiceTemplate(createFlow bool, clientMode bool, useGatewayPath bool) string { var attrMap map[string]string if clientMode { attrMap = accTestPolicyL2VpnServiceCreateClientModeAttributes @@ -234,25 +341,27 @@ func testAccNsxtPolicyL2VpnServiceTemplate(createFlow bool, clientMode bool) str attrMap = accTestPolicyL2VpnServiceUpdateAttributes } } + gatewayOrLocaleServicePath := getGatewayOrLocaleServicePath(useGatewayPath, true) return testAccNsxtPolicyTier0WithEdgeClusterForVPN() + fmt.Sprintf(` resource "nsxt_policy_l2_vpn_service" "test" { - display_name = "%s" - description = "%s" - locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path - enable_hub = "%s" - mode = "%s" - encap_ip_pool = ["%s"] + display_name = "%s" + description = "%s" + %s + enable_hub = "%s" + mode = "%s" + encap_ip_pool = ["%s"] tag { scope = "scope1" tag = "tag1" } - }`, attrMap["display_name"], attrMap["description"], attrMap["enable_hub"], attrMap["mode"], attrMap["encap_ip_pool"]) + }`, attrMap["display_name"], attrMap["description"], gatewayOrLocaleServicePath, attrMap["enable_hub"], attrMap["mode"], attrMap["encap_ip_pool"]) } -func testAccNsxtPolicyL2VpnServiceMinimalistic() string { +func testAccNsxtPolicyL2VpnServiceMinimalistic(useGatewayPath bool) string { + gatewayOrLocaleServicePath := getGatewayOrLocaleServicePath(useGatewayPath, true) return testAccNsxtPolicyTier0WithEdgeClusterForVPN() + fmt.Sprintf(` resource "nsxt_policy_l2_vpn_service" "test" { display_name = "%s" - locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path - }`, accTestPolicyL2VpnServiceUpdateAttributes["display_name"]) + %s + }`, accTestPolicyL2VpnServiceUpdateAttributes["display_name"], gatewayOrLocaleServicePath) } diff --git a/nsxt/resource_nsxt_policy_l2_vpn_session.go b/nsxt/resource_nsxt_policy_l2_vpn_session.go index 6d37aef9b..999619e6e 100644 --- a/nsxt/resource_nsxt_policy_l2_vpn_session.go +++ b/nsxt/resource_nsxt_policy_l2_vpn_session.go @@ -10,8 +10,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" - t0_l2vpn_services "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services/l2vpn_services" - t1_l2vpn_services "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services/l2vpn_services" + t0_l2vpn_services "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services" + t0_l2vpn_nested_services "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services/l2vpn_services" + t1_l2vpn_services "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services" + t1_l2vpn_nested_services "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services/l2vpn_services" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" ) @@ -60,13 +62,14 @@ func resourceNsxtPolicyL2VPNSession() *schema.Resource { Type: schema.TypeString, Description: "The traffic direction apply to the MSS clamping", Optional: true, + Default: model.L2TcpMaxSegmentSizeClamping_DIRECTION_BOTH, ValidateFunc: validation.StringInSlice(L2VpnSessionTCPSegmentClampingDirection, false), }, "max_segment_size": { - Type: schema.TypeInt, - Description: "Maximum amount of data the host will accept in a Tcp segment.", - Optional: true, - ValidateFunc: validation.IntBetween(108, 8860), + Type: schema.TypeInt, + Description: "Maximum amount of data the host will accept in a Tcp segment.", + Optional: true, + Computed: true, }, "local_address": { Type: schema.TypeString, @@ -127,8 +130,10 @@ func resourceNsxtPolicyL2VPNSessionCreate(d *schema.ResourceData, m interface{}) maxSegmentSize := int64(d.Get("max_segment_size").(int)) if direction != "" { l2TcpMSSClamping := model.L2TcpMaxSegmentSizeClamping{ - Direction: &direction, - MaxSegmentSize: &maxSegmentSize, + Direction: &direction, + } + if maxSegmentSize > 0 { + l2TcpMSSClamping.MaxSegmentSize = &maxSegmentSize } obj.TcpMssClamping = &l2TcpMSSClamping } @@ -146,11 +151,21 @@ func resourceNsxtPolicyL2VPNSessionCreate(d *schema.ResourceData, m interface{}) } if isT0 { - client := t0_l2vpn_services.NewSessionsClient(connector) - err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + if localeServiceID == "" { + client := t0_l2vpn_services.NewSessionsClient(connector) + err = client.Patch(gwID, serviceID, id, obj) + } else { + client := t0_l2vpn_nested_services.NewSessionsClient(connector) + err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + } } else { - client := t1_l2vpn_services.NewSessionsClient(connector) - err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + if localeServiceID == "" { + client := t1_l2vpn_services.NewSessionsClient(connector) + err = client.Patch(gwID, serviceID, id, obj) + } else { + client := t1_l2vpn_nested_services.NewSessionsClient(connector) + err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + } } if err != nil { return handleCreateError("L2VPNSession", id, err) @@ -164,17 +179,22 @@ func resourceNsxtPolicyL2VPNSessionCreate(d *schema.ResourceData, m interface{}) func parseL2VPNServicePolicyPath(path string) (bool, string, string, string, error) { segs := strings.Split(path, "/") - // Path should be like /infra/tier-1s/aaa/l2vpn-services/default/ipsec-vpn-services/ccc + // Path should be like /infra/tier-1s/aaa/locale-services/bbb/l2vpn-services/ccc + // or /infra/tier-0s/aaa/l2vpn-services/bbb segCount := len(segs) - if (segCount < 8) || (segs[segCount-2] != "l2vpn-services") { + if segCount < 6 || segCount > 8 || (segs[segCount-2] != "l2vpn-services") { // error - this is not a segment path return false, "", "", "", fmt.Errorf("Invalid L2 VPN service path %s", path) } serviceID := segs[segCount-1] - localeServiceID := segs[5] gwPath := strings.Join(segs[:4], "/") + localeServiceID := "" + if segCount == 8 { + localeServiceID = segs[5] + } + isT0, gwID := parseGatewayPolicyPath(gwPath) return isT0, gwID, localeServiceID, serviceID, nil } @@ -193,11 +213,21 @@ func resourceNsxtPolicyL2VPNSessionRead(d *schema.ResourceData, m interface{}) e var obj model.L2VPNSession if isT0 { - client := t0_l2vpn_services.NewSessionsClient(connector) - obj, err = client.Get(gwID, localeServiceID, serviceID, id) + if localeServiceID == "" { + client := t0_l2vpn_services.NewSessionsClient(connector) + obj, err = client.Get(gwID, serviceID, id) + } else { + client := t0_l2vpn_nested_services.NewSessionsClient(connector) + obj, err = client.Get(gwID, localeServiceID, serviceID, id) + } } else { - client := t1_l2vpn_services.NewSessionsClient(connector) - obj, err = client.Get(gwID, localeServiceID, serviceID, id) + if localeServiceID == "" { + client := t1_l2vpn_services.NewSessionsClient(connector) + obj, err = client.Get(gwID, serviceID, id) + } else { + client := t1_l2vpn_nested_services.NewSessionsClient(connector) + obj, err = client.Get(gwID, localeServiceID, serviceID, id) + } } if err != nil { return handleReadError(d, "L2VPNSession", id, err) @@ -238,11 +268,21 @@ func resourceNsxtPolicyL2VPNSessionRead(d *schema.ResourceData, m interface{}) e func resourceNsxtPolicyL2VpnSessionExists(isT0 bool, gwID string, localeServiceID string, serviceID string, sessionID string, connector client.Connector) (bool, error) { var err error if isT0 { - client := t0_l2vpn_services.NewSessionsClient(connector) - _, err = client.Get(gwID, localeServiceID, serviceID, sessionID) + if localeServiceID == "" { + client := t0_l2vpn_services.NewSessionsClient(connector) + _, err = client.Get(gwID, serviceID, sessionID) + } else { + client := t0_l2vpn_nested_services.NewSessionsClient(connector) + _, err = client.Get(gwID, localeServiceID, serviceID, sessionID) + } } else { - client := t1_l2vpn_services.NewSessionsClient(connector) - _, err = client.Get(gwID, localeServiceID, serviceID, sessionID) + if localeServiceID == "" { + client := t1_l2vpn_services.NewSessionsClient(connector) + _, err = client.Get(gwID, serviceID, sessionID) + } else { + client := t1_l2vpn_nested_services.NewSessionsClient(connector) + _, err = client.Get(gwID, localeServiceID, serviceID, sessionID) + } } if err == nil { @@ -289,8 +329,10 @@ func resourceNsxtPolicyL2VPNSessionUpdate(d *schema.ResourceData, m interface{}) maxSegmentSize := int64(d.Get("max_segment_size").(int)) if direction != "" { l2TcpMSSClamping := model.L2TcpMaxSegmentSizeClamping{ - Direction: &direction, - MaxSegmentSize: &maxSegmentSize, + Direction: &direction, + } + if maxSegmentSize > 0 { + l2TcpMSSClamping.MaxSegmentSize = &maxSegmentSize } obj.TcpMssClamping = &l2TcpMSSClamping } @@ -307,11 +349,21 @@ func resourceNsxtPolicyL2VPNSessionUpdate(d *schema.ResourceData, m interface{}) } } if isT0 { - client := t0_l2vpn_services.NewSessionsClient(connector) - err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + if localeServiceID == "" { + client := t0_l2vpn_services.NewSessionsClient(connector) + err = client.Patch(gwID, serviceID, id, obj) + } else { + client := t0_l2vpn_nested_services.NewSessionsClient(connector) + err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + } } else { - client := t1_l2vpn_services.NewSessionsClient(connector) - err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + if localeServiceID == "" { + client := t1_l2vpn_services.NewSessionsClient(connector) + err = client.Patch(gwID, serviceID, id, obj) + } else { + client := t1_l2vpn_nested_services.NewSessionsClient(connector) + err = client.Patch(gwID, localeServiceID, serviceID, id, obj) + } } if err != nil { @@ -336,11 +388,21 @@ func resourceNsxtPolicyL2VPNSessionDelete(d *schema.ResourceData, m interface{}) connector := getPolicyConnector(m) if isT0 { - client := t0_l2vpn_services.NewSessionsClient(connector) - err = client.Delete(gwID, localeServiceID, serviceID, id) + if localeServiceID == "" { + client := t0_l2vpn_services.NewSessionsClient(connector) + err = client.Delete(gwID, serviceID, id) + } else { + client := t0_l2vpn_nested_services.NewSessionsClient(connector) + err = client.Delete(gwID, localeServiceID, serviceID, id) + } } else { - client := t1_l2vpn_services.NewSessionsClient(connector) - err = client.Delete(gwID, localeServiceID, serviceID, id) + if localeServiceID == "" { + client := t1_l2vpn_services.NewSessionsClient(connector) + err = client.Delete(gwID, serviceID, id) + } else { + client := t1_l2vpn_nested_services.NewSessionsClient(connector) + err = client.Delete(gwID, localeServiceID, serviceID, id) + } } if err != nil { diff --git a/nsxt/resource_nsxt_policy_l2_vpn_session_test.go b/nsxt/resource_nsxt_policy_l2_vpn_session_test.go index 81ec5d98f..4c80b48a1 100644 --- a/nsxt/resource_nsxt_policy_l2_vpn_session_test.go +++ b/nsxt/resource_nsxt_policy_l2_vpn_session_test.go @@ -39,14 +39,14 @@ func TestAccResourceNsxtPolicyL2VpnSession_basic(t *testing.T) { testResourceName := testAccL2VpnSessionResourceName resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t); testAccNSXVersionLessThan(t, "3.2.0") }, + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t); testAccNSXVersion(t, "3.2.0") }, Providers: testAccProviders, CheckDestroy: func(state *terraform.State) error { return testAccNsxtPolicyL2VpnSessionCheckDestroy(state, accTestPolicyL2VpnSessionCreateAttributes["display_name"]) }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyL2VpnSessionTestTemplate(true, true), + Config: testAccNsxtPolicyL2VpnSessionTestTemplate(true, true, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnSessionExists(accTestPolicyL2VpnSessionCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnSessionCreateAttributes["display_name"]), @@ -66,7 +66,7 @@ func TestAccResourceNsxtPolicyL2VpnSession_basic(t *testing.T) { ), }, { - Config: testAccNsxtPolicyL2VpnSessionTestTemplate(false, true), + Config: testAccNsxtPolicyL2VpnSessionTestTemplate(false, true, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnSessionExists(accTestPolicyL2VpnSessionUpdateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnSessionUpdateAttributes["display_name"]), @@ -86,7 +86,7 @@ func TestAccResourceNsxtPolicyL2VpnSession_basic(t *testing.T) { ), }, { - Config: testAccNsxtPolicyL2VpnSessionMinimalistic(), + Config: testAccNsxtPolicyL2VpnSessionMinimalistic(false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnSessionExists(accTestPolicyL2VpnSessionCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnSessionCreateAttributes["display_name"]), @@ -112,14 +112,14 @@ func TestAccResourceNsxtPolicyL2VpnSession_import(t *testing.T) { testResourceName := testAccL2VpnSessionResourceName resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t); testAccNSXVersionLessThan(t, "3.2.0") }, + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t); testAccNSXVersion(t, "3.2.0") }, Providers: testAccProviders, CheckDestroy: func(state *terraform.State) error { return testAccNsxtPolicyL2VpnSessionCheckDestroy(state, accTestPolicyL2VpnSessionCreateAttributes["display_name"]) }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyL2VpnSessionMinimalistic(), + Config: testAccNsxtPolicyL2VpnSessionMinimalistic(false), }, { ResourceName: testResourceName, @@ -135,14 +135,14 @@ func TestAccResourceNsxtPolicyL2VpnSession_tier1(t *testing.T) { testResourceName := testAccL2VpnSessionResourceName resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t); testAccNSXVersionLessThan(t, "3.2.0") }, + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t); testAccNSXVersion(t, "3.2.0") }, Providers: testAccProviders, CheckDestroy: func(state *terraform.State) error { return testAccNsxtPolicyL2VpnSessionCheckDestroy(state, accTestPolicyL2VpnSessionCreateAttributes["display_name"]) }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyL2VpnSessionTestTemplate(true, false), + Config: testAccNsxtPolicyL2VpnSessionTestTemplate(true, false, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnSessionExists(accTestPolicyL2VpnSessionCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnSessionCreateAttributes["display_name"]), @@ -162,7 +162,7 @@ func TestAccResourceNsxtPolicyL2VpnSession_tier1(t *testing.T) { ), }, { - Config: testAccNsxtPolicyL2VpnSessionTestTemplate(false, false), + Config: testAccNsxtPolicyL2VpnSessionTestTemplate(false, false, false), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyL2VpnSessionExists(accTestPolicyL2VpnSessionUpdateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyL2VpnSessionUpdateAttributes["display_name"]), @@ -263,13 +263,14 @@ func testAccNsxtPolicyL2VpnSessionCheckDestroy(state *terraform.State, displayNa return nil } -func testAccNsxtPolicyL2VpnSessionPreConditionTemplate(isT0 bool) string { +func testAccNsxtPolicyL2VpnSessionPreConditionTemplate(isT0 bool, useGatewayPath bool) string { + gatewayOrLocaleServicePath := getGatewayOrLocaleServicePath(useGatewayPath, isT0) var vpnServiceTemplate string if isT0 { vpnServiceTemplate = fmt.Sprintf(` resource "nsxt_policy_l2_vpn_service" "test_l2_svc" { display_name = "%s" - locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path + %s enable_hub = true mode = "SERVER" encap_ip_pool = ["192.168.10.0/24"] @@ -277,23 +278,23 @@ resource "nsxt_policy_l2_vpn_service" "test_l2_svc" { resource "nsxt_policy_ipsec_vpn_service" "test_ipsec_svc" { display_name = "%s" - locale_service_path = one(nsxt_policy_tier0_gateway.test.locale_service).path + %s } -`, l2VpnResourceName, l2VpnResourceName) +`, l2VpnResourceName, gatewayOrLocaleServicePath, l2VpnResourceName, gatewayOrLocaleServicePath) } else { vpnServiceTemplate = fmt.Sprintf(` resource "nsxt_policy_l2_vpn_service" "test_l2_svc" { display_name = "%s" - locale_service_path = one(nsxt_policy_tier1_gateway.test.locale_service).path + %s enable_hub = true mode = "SERVER" encap_ip_pool = ["192.168.10.0/24"] } resource "nsxt_policy_ipsec_vpn_service" "test_ipsec_svc" { display_name = "%s" - locale_service_path = one(nsxt_policy_tier1_gateway.test.locale_service).path + %s } -`, l2VpnResourceName, l2VpnResourceName) +`, l2VpnResourceName, gatewayOrLocaleServicePath, l2VpnResourceName, gatewayOrLocaleServicePath) } return vpnServiceTemplate + fmt.Sprintf(` resource "nsxt_policy_ipsec_vpn_ike_profile" "test" { @@ -346,9 +347,9 @@ resource "nsxt_policy_ipsec_vpn_session" "test" { `, l2VpnResourceName, l2VpnResourceName, l2VpnResourceName, l2VpnResourceName, l2VpnResourceName) } -func testAccNsxtPolicyL2VpnSessionTestTemplate(createFlow bool, isT0 bool) string { +func testAccNsxtPolicyL2VpnSessionTestTemplate(createFlow bool, isT0 bool, useGatewayPath bool) string { return testAccNsxtPolicyGatewayTemplate(isT0) + - testAccNsxtPolicyL2VpnSessionPreConditionTemplate(isT0) + + testAccNsxtPolicyL2VpnSessionPreConditionTemplate(isT0, useGatewayPath) + testAccNsxtPolicyL2VpnSessionTemplate(createFlow) } @@ -380,10 +381,10 @@ resource "nsxt_policy_l2_vpn_session" "test" { `, attrMap["display_name"], attrMap["description"], attrMap["direction"], attrMap["max_segment_size"], attrMap["local_address"], attrMap["peer_address"], attrMap["protocol"]) } -func testAccNsxtPolicyL2VpnSessionMinimalistic() string { +func testAccNsxtPolicyL2VpnSessionMinimalistic(useGatewayPath bool) string { attrMap := accTestPolicyL2VpnSessionCreateAttributes return testAccNsxtPolicyTier0WithEdgeClusterForVPN() + - testAccNsxtPolicyL2VpnSessionPreConditionTemplate(true) + fmt.Sprintf(` + testAccNsxtPolicyL2VpnSessionPreConditionTemplate(true, useGatewayPath) + fmt.Sprintf(` resource "nsxt_policy_l2_vpn_session" "test" { display_name = "%s" service_path = nsxt_policy_l2_vpn_service.test_l2_svc.path diff --git a/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/L2vpnServicesPackageTypes.go b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/L2vpnServicesPackageTypes.go new file mode 100644 index 000000000..3e6183939 --- /dev/null +++ b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/L2vpnServicesPackageTypes.go @@ -0,0 +1,11 @@ +// Copyright © 2019-2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: BSD-2-Clause + +// Auto generated code. DO NOT EDIT. + +// Data type definitions file for package: com.vmware.nsx_policy.infra.tier_0s.l2vpn_services. +// Includes binding types of a top level structures and enumerations. +// Shared by client-side stubs and server-side skeletons to ensure type +// compatibility. + +package l2vpn_services diff --git a/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsClient.go b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsClient.go new file mode 100644 index 000000000..b03689d35 --- /dev/null +++ b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsClient.go @@ -0,0 +1,335 @@ +// Copyright © 2019-2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: BSD-2-Clause + +// Auto generated code. DO NOT EDIT. + +// Interface file for service: Sessions +// Used by client-side stubs. + +package l2vpn_services + +import ( + vapiStdErrors_ "github.com/vmware/vsphere-automation-sdk-go/lib/vapi/std/errors" + vapiBindings_ "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" + vapiCore_ "github.com/vmware/vsphere-automation-sdk-go/runtime/core" + vapiProtocolClient_ "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" + nsx_policyModel "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" +) + +const _ = vapiCore_.SupportedByRuntimeVersion2 + +type SessionsClient interface { + + // Create or patch an L2VPN session under Tier-0 from Peer Codes. In addition to the L2VPN Session, the IPSec VPN Session, along with the IKE, Tunnel, and DPD Profiles are created and owned by the system. IPSec VPN Service and Local Endpoint are created only when required, i.e., an IPSec VPN Service does not already exist, or an IPSec VPN Local Endpoint with same local address does not already exist. Updating the L2VPN Session can be performed only through this API by specifying new peer codes. Use of specific APIs to update the L2VPN Session and the different resources associated with it is not allowed, except for IPSec VPN Service and Local Endpoint, resources that are not system owned. API supported only when L2VPN Service is in Client Mode. + // + // @param tier0IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @param l2VPNSessionDataParam (required) + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Createwithpeercode(tier0IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionDataParam nsx_policyModel.L2VPNSessionData) error + + // Delete L2VPN session under Tier-0. When L2VPN Service is in CLIENT Mode, the L2VPN Session is deleted along with its transpot tunnels and related resources. + // + // @param tier0IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Delete(tier0IdParam string, serviceIdParam string, sessionIdParam string) error + + // Get L2VPN session under Tier-0. + // + // @param tier0IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @return com.vmware.nsx_policy.model.L2VPNSession + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Get(tier0IdParam string, serviceIdParam string, sessionIdParam string) (nsx_policyModel.L2VPNSession, error) + + // Get paginated list of all L2VPN sessions under Tier-0. + // + // @param tier0IdParam (required) + // @param serviceIdParam (required) + // @param cursorParam Opaque cursor to be used for getting next page of records (supplied by current result page) (optional) + // @param includeMarkForDeleteObjectsParam Include objects that are marked for deletion in results (optional, default to false) + // @param includedFieldsParam Comma separated list of fields that should be included in query result (optional) + // @param pageSizeParam Maximum number of results to return in this page (server may return fewer) (optional, default to 1000) + // @param sortAscendingParam (optional) + // @param sortByParam Field by which records are sorted (optional) + // @return com.vmware.nsx_policy.model.L2VPNSessionListResult + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + List(tier0IdParam string, serviceIdParam string, cursorParam *string, includeMarkForDeleteObjectsParam *bool, includedFieldsParam *string, pageSizeParam *int64, sortAscendingParam *bool, sortByParam *string) (nsx_policyModel.L2VPNSessionListResult, error) + + // Create or patch an L2VPN session under Tier-0. API supported only when L2VPN Service is in Server Mode. + // + // @param tier0IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @param l2VPNSessionParam (required) + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Patch(tier0IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) error + + // Create or fully replace L2VPN session under Tier-0. API supported only when L2VPN Service is in Server Mode. Revision is optional for creation and required for update. + // + // @param tier0IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @param l2VPNSessionParam (required) + // @return com.vmware.nsx_policy.model.L2VPNSession + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Update(tier0IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) (nsx_policyModel.L2VPNSession, error) +} + +type sessionsClient struct { + connector vapiProtocolClient_.Connector + interfaceDefinition vapiCore_.InterfaceDefinition + errorsBindingMap map[string]vapiBindings_.BindingType +} + +func NewSessionsClient(connector vapiProtocolClient_.Connector) *sessionsClient { + interfaceIdentifier := vapiCore_.NewInterfaceIdentifier("com.vmware.nsx_policy.infra.tier_0s.l2vpn_services.sessions") + methodIdentifiers := map[string]vapiCore_.MethodIdentifier{ + "createwithpeercode": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "createwithpeercode"), + "delete": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "delete"), + "get": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "get"), + "list": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "list"), + "patch": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "patch"), + "update": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "update"), + } + interfaceDefinition := vapiCore_.NewInterfaceDefinition(interfaceIdentifier, methodIdentifiers) + errorsBindingMap := make(map[string]vapiBindings_.BindingType) + + sIface := sessionsClient{interfaceDefinition: interfaceDefinition, errorsBindingMap: errorsBindingMap, connector: connector} + return &sIface +} + +func (sIface *sessionsClient) GetErrorBindingType(errorName string) vapiBindings_.BindingType { + if entry, ok := sIface.errorsBindingMap[errorName]; ok { + return entry + } + return vapiStdErrors_.ERROR_BINDINGS_MAP[errorName] +} + +func (sIface *sessionsClient) Createwithpeercode(tier0IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionDataParam nsx_policyModel.L2VPNSessionData) error { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsCreatewithpeercodeRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsCreatewithpeercodeInputType(), typeConverter) + sv.AddStructField("Tier0Id", tier0IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + sv.AddStructField("L2VPNSessionData", l2VPNSessionDataParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + return vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_0s.l2vpn_services.sessions", "createwithpeercode", inputDataValue, executionContext) + if methodResult.IsSuccess() { + return nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return vapiBindings_.VAPIerrorsToError(errorInError) + } + return methodError.(error) + } +} + +func (sIface *sessionsClient) Delete(tier0IdParam string, serviceIdParam string, sessionIdParam string) error { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsDeleteRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsDeleteInputType(), typeConverter) + sv.AddStructField("Tier0Id", tier0IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + return vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_0s.l2vpn_services.sessions", "delete", inputDataValue, executionContext) + if methodResult.IsSuccess() { + return nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return vapiBindings_.VAPIerrorsToError(errorInError) + } + return methodError.(error) + } +} + +func (sIface *sessionsClient) Get(tier0IdParam string, serviceIdParam string, sessionIdParam string) (nsx_policyModel.L2VPNSession, error) { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsGetRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsGetInputType(), typeConverter) + sv.AddStructField("Tier0Id", tier0IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + var emptyOutput nsx_policyModel.L2VPNSession + return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_0s.l2vpn_services.sessions", "get", inputDataValue, executionContext) + var emptyOutput nsx_policyModel.L2VPNSession + if methodResult.IsSuccess() { + output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), SessionsGetOutputType()) + if errorInOutput != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput) + } + return output.(nsx_policyModel.L2VPNSession), nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError) + } + return emptyOutput, methodError.(error) + } +} + +func (sIface *sessionsClient) List(tier0IdParam string, serviceIdParam string, cursorParam *string, includeMarkForDeleteObjectsParam *bool, includedFieldsParam *string, pageSizeParam *int64, sortAscendingParam *bool, sortByParam *string) (nsx_policyModel.L2VPNSessionListResult, error) { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsListRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsListInputType(), typeConverter) + sv.AddStructField("Tier0Id", tier0IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("Cursor", cursorParam) + sv.AddStructField("IncludeMarkForDeleteObjects", includeMarkForDeleteObjectsParam) + sv.AddStructField("IncludedFields", includedFieldsParam) + sv.AddStructField("PageSize", pageSizeParam) + sv.AddStructField("SortAscending", sortAscendingParam) + sv.AddStructField("SortBy", sortByParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + var emptyOutput nsx_policyModel.L2VPNSessionListResult + return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_0s.l2vpn_services.sessions", "list", inputDataValue, executionContext) + var emptyOutput nsx_policyModel.L2VPNSessionListResult + if methodResult.IsSuccess() { + output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), SessionsListOutputType()) + if errorInOutput != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput) + } + return output.(nsx_policyModel.L2VPNSessionListResult), nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError) + } + return emptyOutput, methodError.(error) + } +} + +func (sIface *sessionsClient) Patch(tier0IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) error { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsPatchRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsPatchInputType(), typeConverter) + sv.AddStructField("Tier0Id", tier0IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + sv.AddStructField("L2VPNSession", l2VPNSessionParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + return vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_0s.l2vpn_services.sessions", "patch", inputDataValue, executionContext) + if methodResult.IsSuccess() { + return nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return vapiBindings_.VAPIerrorsToError(errorInError) + } + return methodError.(error) + } +} + +func (sIface *sessionsClient) Update(tier0IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) (nsx_policyModel.L2VPNSession, error) { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsUpdateRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsUpdateInputType(), typeConverter) + sv.AddStructField("Tier0Id", tier0IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + sv.AddStructField("L2VPNSession", l2VPNSessionParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + var emptyOutput nsx_policyModel.L2VPNSession + return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_0s.l2vpn_services.sessions", "update", inputDataValue, executionContext) + var emptyOutput nsx_policyModel.L2VPNSession + if methodResult.IsSuccess() { + output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), SessionsUpdateOutputType()) + if errorInOutput != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput) + } + return output.(nsx_policyModel.L2VPNSession), nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError) + } + return emptyOutput, methodError.(error) + } +} diff --git a/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsTypes.go b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsTypes.go new file mode 100644 index 000000000..fe7257737 --- /dev/null +++ b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services/SessionsTypes.go @@ -0,0 +1,447 @@ +// Copyright © 2019-2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: BSD-2-Clause + +// Auto generated code. DO NOT EDIT. + +// Data type definitions file for service: Sessions. +// Includes binding types of a structures and enumerations defined in the service. +// Shared by client-side stubs and server-side skeletons to ensure type +// compatibility. + +package l2vpn_services + +import ( + vapiBindings_ "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" + vapiData_ "github.com/vmware/vsphere-automation-sdk-go/runtime/data" + vapiProtocol_ "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol" + nsx_policyModel "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" + "reflect" +) + +func sessionsCreatewithpeercodeInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session_data"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionDataBindingType) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session_data"] = "L2VPNSessionData" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsCreatewithpeercodeOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewVoidType() +} + +func sessionsCreatewithpeercodeRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session_data"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionDataBindingType) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session_data"] = "L2VPNSessionData" + paramsTypeMap["tier0_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["l2_VPN_session_data"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionDataBindingType) + paramsTypeMap["tier0Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier0_id"] = "tier0Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "action=create_with_peer_code", + "l2_VPN_session_data", + "POST", + "/policy/api/v1/infra/tier-0s/{tier0Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 204, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsDeleteInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsDeleteOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewVoidType() +} + +func sessionsDeleteRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + paramsTypeMap["tier0_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier0Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier0_id"] = "tier0Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "", + "DELETE", + "/policy/api/v1/infra/tier-0s/{tier0Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 204, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsGetInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsGetOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) +} + +func sessionsGetRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + paramsTypeMap["tier0_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier0Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier0_id"] = "tier0Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "", + "GET", + "/policy/api/v1/infra/tier-0s/{tier0Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 200, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsListInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["cursor"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["include_mark_for_delete_objects"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["included_fields"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["page_size"] = vapiBindings_.NewOptionalType(vapiBindings_.NewIntegerType()) + fields["sort_ascending"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["sort_by"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["cursor"] = "Cursor" + fieldNameMap["include_mark_for_delete_objects"] = "IncludeMarkForDeleteObjects" + fieldNameMap["included_fields"] = "IncludedFields" + fieldNameMap["page_size"] = "PageSize" + fieldNameMap["sort_ascending"] = "SortAscending" + fieldNameMap["sort_by"] = "SortBy" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsListOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionListResultBindingType) +} + +func sessionsListRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["cursor"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["include_mark_for_delete_objects"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["included_fields"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["page_size"] = vapiBindings_.NewOptionalType(vapiBindings_.NewIntegerType()) + fields["sort_ascending"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["sort_by"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["cursor"] = "Cursor" + fieldNameMap["include_mark_for_delete_objects"] = "IncludeMarkForDeleteObjects" + fieldNameMap["included_fields"] = "IncludedFields" + fieldNameMap["page_size"] = "PageSize" + fieldNameMap["sort_ascending"] = "SortAscending" + fieldNameMap["sort_by"] = "SortBy" + paramsTypeMap["cursor"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + paramsTypeMap["tier0_id"] = vapiBindings_.NewStringType() + paramsTypeMap["sort_ascending"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + paramsTypeMap["included_fields"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["sort_by"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + paramsTypeMap["include_mark_for_delete_objects"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + paramsTypeMap["page_size"] = vapiBindings_.NewOptionalType(vapiBindings_.NewIntegerType()) + paramsTypeMap["tier0Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + pathParams["tier0_id"] = "tier0Id" + pathParams["service_id"] = "serviceId" + queryParams["cursor"] = "cursor" + queryParams["sort_ascending"] = "sort_ascending" + queryParams["included_fields"] = "included_fields" + queryParams["sort_by"] = "sort_by" + queryParams["include_mark_for_delete_objects"] = "include_mark_for_delete_objects" + queryParams["page_size"] = "page_size" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "", + "GET", + "/policy/api/v1/infra/tier-0s/{tier0Id}/l2vpn-services/{serviceId}/sessions", + "", + resultHeaders, + 200, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsPatchInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsPatchOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewVoidType() +} + +func sessionsPatchRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + paramsTypeMap["tier0_id"] = vapiBindings_.NewStringType() + paramsTypeMap["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier0Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier0_id"] = "tier0Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "l2_VPN_session", + "PATCH", + "/policy/api/v1/infra/tier-0s/{tier0Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 204, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsUpdateInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsUpdateOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) +} + +func sessionsUpdateRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier0_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier0_id"] = "Tier0Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + paramsTypeMap["tier0_id"] = vapiBindings_.NewStringType() + paramsTypeMap["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier0Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier0_id"] = "tier0Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "l2_VPN_session", + "PUT", + "/policy/api/v1/infra/tier-0s/{tier0Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 200, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} diff --git a/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/L2vpnServicesPackageTypes.go b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/L2vpnServicesPackageTypes.go new file mode 100644 index 000000000..0ab150e77 --- /dev/null +++ b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/L2vpnServicesPackageTypes.go @@ -0,0 +1,11 @@ +// Copyright © 2019-2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: BSD-2-Clause + +// Auto generated code. DO NOT EDIT. + +// Data type definitions file for package: com.vmware.nsx_policy.infra.tier_1s.l2vpn_services. +// Includes binding types of a top level structures and enumerations. +// Shared by client-side stubs and server-side skeletons to ensure type +// compatibility. + +package l2vpn_services diff --git a/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsClient.go b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsClient.go new file mode 100644 index 000000000..9c79906dd --- /dev/null +++ b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsClient.go @@ -0,0 +1,335 @@ +// Copyright © 2019-2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: BSD-2-Clause + +// Auto generated code. DO NOT EDIT. + +// Interface file for service: Sessions +// Used by client-side stubs. + +package l2vpn_services + +import ( + vapiStdErrors_ "github.com/vmware/vsphere-automation-sdk-go/lib/vapi/std/errors" + vapiBindings_ "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" + vapiCore_ "github.com/vmware/vsphere-automation-sdk-go/runtime/core" + vapiProtocolClient_ "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" + nsx_policyModel "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" +) + +const _ = vapiCore_.SupportedByRuntimeVersion2 + +type SessionsClient interface { + + // Create or patch an L2VPN session under Tier-1 from Peer Codes. In addition to the L2VPN Session, the IPSec VPN Session, along with the IKE, Tunnel, and DPD Profiles are created and owned by the system. IPSec VPN Service and Local Endpoint are created only when required, i.e., an IPSec VPN Service does not already exist, or an IPSec VPN Local Endpoint with same local address does not already exist. Updating the L2VPN Session can be performed only through this API by specifying new peer codes. Use of specific APIs to update the L2VPN Session and the different resources associated with it is not allowed, except for IPSec VPN Service and Local Endpoint, resources that are not system owned. API supported only when L2VPN Service is in Client Mode. + // + // @param tier1IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @param l2VPNSessionDataParam (required) + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Createwithpeercode(tier1IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionDataParam nsx_policyModel.L2VPNSessionData) error + + // Delete L2VPN session under Tier-1. When L2VPN Service is in CLIENT Mode, the L2VPN Session is deleted along with its transpot tunnels and related resources. + // + // @param tier1IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Delete(tier1IdParam string, serviceIdParam string, sessionIdParam string) error + + // Get L2VPN session under Tier-1. + // + // @param tier1IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @return com.vmware.nsx_policy.model.L2VPNSession + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Get(tier1IdParam string, serviceIdParam string, sessionIdParam string) (nsx_policyModel.L2VPNSession, error) + + // Get paginated list of all L2VPN sessions under Tier-1. + // + // @param tier1IdParam (required) + // @param serviceIdParam (required) + // @param cursorParam Opaque cursor to be used for getting next page of records (supplied by current result page) (optional) + // @param includeMarkForDeleteObjectsParam Include objects that are marked for deletion in results (optional, default to false) + // @param includedFieldsParam Comma separated list of fields that should be included in query result (optional) + // @param pageSizeParam Maximum number of results to return in this page (server may return fewer) (optional, default to 1000) + // @param sortAscendingParam (optional) + // @param sortByParam Field by which records are sorted (optional) + // @return com.vmware.nsx_policy.model.L2VPNSessionListResult + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + List(tier1IdParam string, serviceIdParam string, cursorParam *string, includeMarkForDeleteObjectsParam *bool, includedFieldsParam *string, pageSizeParam *int64, sortAscendingParam *bool, sortByParam *string) (nsx_policyModel.L2VPNSessionListResult, error) + + // Create or patch an L2VPN session under Tier-1. API supported only when L2VPN Service is in Server Mode. + // + // @param tier1IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @param l2VPNSessionParam (required) + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Patch(tier1IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) error + + // Create or fully replace L2VPN session under Tier-1. API supported only when L2VPN Service is in Server Mode. Revision is optional for creation and required for update. + // + // @param tier1IdParam (required) + // @param serviceIdParam (required) + // @param sessionIdParam (required) + // @param l2VPNSessionParam (required) + // @return com.vmware.nsx_policy.model.L2VPNSession + // + // @throws InvalidRequest Bad Request, Precondition Failed + // @throws Unauthorized Forbidden + // @throws ServiceUnavailable Service Unavailable + // @throws InternalServerError Internal Server Error + // @throws NotFound Not Found + Update(tier1IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) (nsx_policyModel.L2VPNSession, error) +} + +type sessionsClient struct { + connector vapiProtocolClient_.Connector + interfaceDefinition vapiCore_.InterfaceDefinition + errorsBindingMap map[string]vapiBindings_.BindingType +} + +func NewSessionsClient(connector vapiProtocolClient_.Connector) *sessionsClient { + interfaceIdentifier := vapiCore_.NewInterfaceIdentifier("com.vmware.nsx_policy.infra.tier_1s.l2vpn_services.sessions") + methodIdentifiers := map[string]vapiCore_.MethodIdentifier{ + "createwithpeercode": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "createwithpeercode"), + "delete": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "delete"), + "get": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "get"), + "list": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "list"), + "patch": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "patch"), + "update": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "update"), + } + interfaceDefinition := vapiCore_.NewInterfaceDefinition(interfaceIdentifier, methodIdentifiers) + errorsBindingMap := make(map[string]vapiBindings_.BindingType) + + sIface := sessionsClient{interfaceDefinition: interfaceDefinition, errorsBindingMap: errorsBindingMap, connector: connector} + return &sIface +} + +func (sIface *sessionsClient) GetErrorBindingType(errorName string) vapiBindings_.BindingType { + if entry, ok := sIface.errorsBindingMap[errorName]; ok { + return entry + } + return vapiStdErrors_.ERROR_BINDINGS_MAP[errorName] +} + +func (sIface *sessionsClient) Createwithpeercode(tier1IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionDataParam nsx_policyModel.L2VPNSessionData) error { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsCreatewithpeercodeRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsCreatewithpeercodeInputType(), typeConverter) + sv.AddStructField("Tier1Id", tier1IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + sv.AddStructField("L2VPNSessionData", l2VPNSessionDataParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + return vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_1s.l2vpn_services.sessions", "createwithpeercode", inputDataValue, executionContext) + if methodResult.IsSuccess() { + return nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return vapiBindings_.VAPIerrorsToError(errorInError) + } + return methodError.(error) + } +} + +func (sIface *sessionsClient) Delete(tier1IdParam string, serviceIdParam string, sessionIdParam string) error { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsDeleteRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsDeleteInputType(), typeConverter) + sv.AddStructField("Tier1Id", tier1IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + return vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_1s.l2vpn_services.sessions", "delete", inputDataValue, executionContext) + if methodResult.IsSuccess() { + return nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return vapiBindings_.VAPIerrorsToError(errorInError) + } + return methodError.(error) + } +} + +func (sIface *sessionsClient) Get(tier1IdParam string, serviceIdParam string, sessionIdParam string) (nsx_policyModel.L2VPNSession, error) { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsGetRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsGetInputType(), typeConverter) + sv.AddStructField("Tier1Id", tier1IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + var emptyOutput nsx_policyModel.L2VPNSession + return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_1s.l2vpn_services.sessions", "get", inputDataValue, executionContext) + var emptyOutput nsx_policyModel.L2VPNSession + if methodResult.IsSuccess() { + output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), SessionsGetOutputType()) + if errorInOutput != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput) + } + return output.(nsx_policyModel.L2VPNSession), nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError) + } + return emptyOutput, methodError.(error) + } +} + +func (sIface *sessionsClient) List(tier1IdParam string, serviceIdParam string, cursorParam *string, includeMarkForDeleteObjectsParam *bool, includedFieldsParam *string, pageSizeParam *int64, sortAscendingParam *bool, sortByParam *string) (nsx_policyModel.L2VPNSessionListResult, error) { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsListRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsListInputType(), typeConverter) + sv.AddStructField("Tier1Id", tier1IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("Cursor", cursorParam) + sv.AddStructField("IncludeMarkForDeleteObjects", includeMarkForDeleteObjectsParam) + sv.AddStructField("IncludedFields", includedFieldsParam) + sv.AddStructField("PageSize", pageSizeParam) + sv.AddStructField("SortAscending", sortAscendingParam) + sv.AddStructField("SortBy", sortByParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + var emptyOutput nsx_policyModel.L2VPNSessionListResult + return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_1s.l2vpn_services.sessions", "list", inputDataValue, executionContext) + var emptyOutput nsx_policyModel.L2VPNSessionListResult + if methodResult.IsSuccess() { + output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), SessionsListOutputType()) + if errorInOutput != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput) + } + return output.(nsx_policyModel.L2VPNSessionListResult), nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError) + } + return emptyOutput, methodError.(error) + } +} + +func (sIface *sessionsClient) Patch(tier1IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) error { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsPatchRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsPatchInputType(), typeConverter) + sv.AddStructField("Tier1Id", tier1IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + sv.AddStructField("L2VPNSession", l2VPNSessionParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + return vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_1s.l2vpn_services.sessions", "patch", inputDataValue, executionContext) + if methodResult.IsSuccess() { + return nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return vapiBindings_.VAPIerrorsToError(errorInError) + } + return methodError.(error) + } +} + +func (sIface *sessionsClient) Update(tier1IdParam string, serviceIdParam string, sessionIdParam string, l2VPNSessionParam nsx_policyModel.L2VPNSession) (nsx_policyModel.L2VPNSession, error) { + typeConverter := sIface.connector.TypeConverter() + executionContext := sIface.connector.NewExecutionContext() + operationRestMetaData := sessionsUpdateRestMetadata() + executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData) + executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false)) + + sv := vapiBindings_.NewStructValueBuilder(sessionsUpdateInputType(), typeConverter) + sv.AddStructField("Tier1Id", tier1IdParam) + sv.AddStructField("ServiceId", serviceIdParam) + sv.AddStructField("SessionId", sessionIdParam) + sv.AddStructField("L2VPNSession", l2VPNSessionParam) + inputDataValue, inputError := sv.GetStructValue() + if inputError != nil { + var emptyOutput nsx_policyModel.L2VPNSession + return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError) + } + + methodResult := sIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.tier_1s.l2vpn_services.sessions", "update", inputDataValue, executionContext) + var emptyOutput nsx_policyModel.L2VPNSession + if methodResult.IsSuccess() { + output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), SessionsUpdateOutputType()) + if errorInOutput != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput) + } + return output.(nsx_policyModel.L2VPNSession), nil + } else { + methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), sIface.GetErrorBindingType(methodResult.Error().Name())) + if errorInError != nil { + return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError) + } + return emptyOutput, methodError.(error) + } +} diff --git a/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsTypes.go b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsTypes.go new file mode 100644 index 000000000..0f7d672d8 --- /dev/null +++ b/vendor/github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services/SessionsTypes.go @@ -0,0 +1,447 @@ +// Copyright © 2019-2021 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: BSD-2-Clause + +// Auto generated code. DO NOT EDIT. + +// Data type definitions file for service: Sessions. +// Includes binding types of a structures and enumerations defined in the service. +// Shared by client-side stubs and server-side skeletons to ensure type +// compatibility. + +package l2vpn_services + +import ( + vapiBindings_ "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" + vapiData_ "github.com/vmware/vsphere-automation-sdk-go/runtime/data" + vapiProtocol_ "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol" + nsx_policyModel "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" + "reflect" +) + +func sessionsCreatewithpeercodeInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session_data"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionDataBindingType) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session_data"] = "L2VPNSessionData" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsCreatewithpeercodeOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewVoidType() +} + +func sessionsCreatewithpeercodeRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session_data"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionDataBindingType) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session_data"] = "L2VPNSessionData" + paramsTypeMap["tier1_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["l2_VPN_session_data"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionDataBindingType) + paramsTypeMap["tier1Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier1_id"] = "tier1Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "action=create_with_peer_code", + "l2_VPN_session_data", + "POST", + "/policy/api/v1/infra/tier-1s/{tier1Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 204, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsDeleteInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsDeleteOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewVoidType() +} + +func sessionsDeleteRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + paramsTypeMap["tier1_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier1Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier1_id"] = "tier1Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "", + "DELETE", + "/policy/api/v1/infra/tier-1s/{tier1Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 204, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsGetInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsGetOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) +} + +func sessionsGetRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + paramsTypeMap["tier1_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier1Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier1_id"] = "tier1Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "", + "GET", + "/policy/api/v1/infra/tier-1s/{tier1Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 200, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsListInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["cursor"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["include_mark_for_delete_objects"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["included_fields"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["page_size"] = vapiBindings_.NewOptionalType(vapiBindings_.NewIntegerType()) + fields["sort_ascending"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["sort_by"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["cursor"] = "Cursor" + fieldNameMap["include_mark_for_delete_objects"] = "IncludeMarkForDeleteObjects" + fieldNameMap["included_fields"] = "IncludedFields" + fieldNameMap["page_size"] = "PageSize" + fieldNameMap["sort_ascending"] = "SortAscending" + fieldNameMap["sort_by"] = "SortBy" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsListOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionListResultBindingType) +} + +func sessionsListRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["cursor"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["include_mark_for_delete_objects"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["included_fields"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fields["page_size"] = vapiBindings_.NewOptionalType(vapiBindings_.NewIntegerType()) + fields["sort_ascending"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + fields["sort_by"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["cursor"] = "Cursor" + fieldNameMap["include_mark_for_delete_objects"] = "IncludeMarkForDeleteObjects" + fieldNameMap["included_fields"] = "IncludedFields" + fieldNameMap["page_size"] = "PageSize" + fieldNameMap["sort_ascending"] = "SortAscending" + fieldNameMap["sort_by"] = "SortBy" + paramsTypeMap["cursor"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + paramsTypeMap["sort_ascending"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + paramsTypeMap["tier1_id"] = vapiBindings_.NewStringType() + paramsTypeMap["included_fields"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["sort_by"] = vapiBindings_.NewOptionalType(vapiBindings_.NewStringType()) + paramsTypeMap["include_mark_for_delete_objects"] = vapiBindings_.NewOptionalType(vapiBindings_.NewBooleanType()) + paramsTypeMap["page_size"] = vapiBindings_.NewOptionalType(vapiBindings_.NewIntegerType()) + paramsTypeMap["tier1Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + pathParams["tier1_id"] = "tier1Id" + pathParams["service_id"] = "serviceId" + queryParams["cursor"] = "cursor" + queryParams["sort_ascending"] = "sort_ascending" + queryParams["included_fields"] = "included_fields" + queryParams["sort_by"] = "sort_by" + queryParams["include_mark_for_delete_objects"] = "include_mark_for_delete_objects" + queryParams["page_size"] = "page_size" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "", + "GET", + "/policy/api/v1/infra/tier-1s/{tier1Id}/l2vpn-services/{serviceId}/sessions", + "", + resultHeaders, + 200, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsPatchInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsPatchOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewVoidType() +} + +func sessionsPatchRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + paramsTypeMap["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + paramsTypeMap["tier1_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier1Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier1_id"] = "tier1Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "l2_VPN_session", + "PATCH", + "/policy/api/v1/infra/tier-1s/{tier1Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 204, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} + +func sessionsUpdateInputType() vapiBindings_.StructType { + fields := make(map[string]vapiBindings_.BindingType) + fieldNameMap := make(map[string]string) + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + var validators = []vapiBindings_.Validator{} + return vapiBindings_.NewStructType("operation-input", fields, reflect.TypeOf(vapiData_.StructValue{}), fieldNameMap, validators) +} + +func SessionsUpdateOutputType() vapiBindings_.BindingType { + return vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) +} + +func sessionsUpdateRestMetadata() vapiProtocol_.OperationRestMetadata { + fields := map[string]vapiBindings_.BindingType{} + fieldNameMap := map[string]string{} + paramsTypeMap := map[string]vapiBindings_.BindingType{} + pathParams := map[string]string{} + queryParams := map[string]string{} + headerParams := map[string]string{} + dispatchHeaderParams := map[string]string{} + bodyFieldsMap := map[string]string{} + fields["tier1_id"] = vapiBindings_.NewStringType() + fields["service_id"] = vapiBindings_.NewStringType() + fields["session_id"] = vapiBindings_.NewStringType() + fields["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + fieldNameMap["tier1_id"] = "Tier1Id" + fieldNameMap["service_id"] = "ServiceId" + fieldNameMap["session_id"] = "SessionId" + fieldNameMap["l2_VPN_session"] = "L2VPNSession" + paramsTypeMap["l2_VPN_session"] = vapiBindings_.NewReferenceType(nsx_policyModel.L2VPNSessionBindingType) + paramsTypeMap["tier1_id"] = vapiBindings_.NewStringType() + paramsTypeMap["service_id"] = vapiBindings_.NewStringType() + paramsTypeMap["session_id"] = vapiBindings_.NewStringType() + paramsTypeMap["tier1Id"] = vapiBindings_.NewStringType() + paramsTypeMap["serviceId"] = vapiBindings_.NewStringType() + paramsTypeMap["sessionId"] = vapiBindings_.NewStringType() + pathParams["tier1_id"] = "tier1Id" + pathParams["session_id"] = "sessionId" + pathParams["service_id"] = "serviceId" + resultHeaders := map[string]string{} + errorHeaders := map[string]map[string]string{} + return vapiProtocol_.NewOperationRestMetadata( + fields, + fieldNameMap, + paramsTypeMap, + pathParams, + queryParams, + headerParams, + dispatchHeaderParams, + bodyFieldsMap, + "", + "l2_VPN_session", + "PUT", + "/policy/api/v1/infra/tier-1s/{tier1Id}/l2vpn-services/{serviceId}/sessions/{sessionId}", + "", + resultHeaders, + 200, + "", + errorHeaders, + map[string]int{"com.vmware.vapi.std.errors.invalid_request": 400, "com.vmware.vapi.std.errors.unauthorized": 403, "com.vmware.vapi.std.errors.service_unavailable": 503, "com.vmware.vapi.std.errors.internal_server_error": 500, "com.vmware.vapi.std.errors.not_found": 404}) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index f7cef8832..9751b5bd3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -259,6 +259,7 @@ github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcemen github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points/edge_clusters github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/ipsec_vpn_services +github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/l2vpn_services github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services/bgp github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services/ipsec_vpn_services @@ -268,6 +269,7 @@ github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/nat github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/static_routes github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/ipsec_vpn_services +github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/l2vpn_services github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services/ipsec_vpn_services github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services/l2vpn_services diff --git a/website/docs/r/policy_ipsec_vpn_service.html.markdown b/website/docs/r/policy_ipsec_vpn_service.html.markdown index 60a580682..370c8fa3d 100644 --- a/website/docs/r/policy_ipsec_vpn_service.html.markdown +++ b/website/docs/r/policy_ipsec_vpn_service.html.markdown @@ -37,7 +37,8 @@ The following arguments are supported: * `description` - (Optional) Description of the resource. * `tag` - (Optional) A list of scope + tag pairs to associate with this resource. * `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource. -* `locale_service_path` - (Required) Path of the gateway locale service associated with the IPSec VPN Service. +* `locale_service_path` - (Deprecated) Path of the gateway locale service associated with the IPSec VPN Service. +* `gateway_path` - (Optional) Path of gateway associated with the IPSec VPN Service. Note that at least one of `gateway_path` and `locale_service_path` must be specified for the IPSec VPN Service object. * `enabled` - (Optional) Whether this IPSec VPN Service is enabled. Default is `true`. * `ha_sync` - (Optional) Enable/Disable IPSec VPN service HA state sync. Default is `true`. * `ike_log_level` - (Optional) Set of algorithms to be used for message digest during IKE negotiation. Value is one of `DEBUG`, `INFO`, `WARN`, `ERROR` and `EMERGENCY`. Default is `INFO`. diff --git a/website/docs/r/policy_ipsec_vpn_session.html.markdown b/website/docs/r/policy_ipsec_vpn_session.html.markdown index 5a9d53a79..dc3d67289 100644 --- a/website/docs/r/policy_ipsec_vpn_session.html.markdown +++ b/website/docs/r/policy_ipsec_vpn_session.html.markdown @@ -83,8 +83,8 @@ The following arguments are supported: * `sources` - (Optional) List of source subnets. Subnet format is ipv4 CIDR. * `destinations` - (Optional) List of distination subnets. Subnet format is ipv4 CIDR. * `action` - (Optional) `PROTECT` or `BYPASS`. Default is `PROTECT`. -* `direction` - (Optional) The traffic direction apply to the MSS clamping. Value is one of `NONE`, `INBOUND_CONNECTION`, `OUTBOUND_CONNECTION` AND `BOTH`. Must be specified together with `max_segment_size`. -* `max_segment_size` - (Optional) Maximum amount of data the host will accept in a TCP segment. Value is an int between `108` and `8860`. Must be specified together with `direction`. +* `direction` - (Optional) The traffic direction apply to the MSS clamping. Value is one of `NONE`, `INBOUND_CONNECTION`, `OUTBOUND_CONNECTION` AND `BOTH`. +* `max_segment_size` - (Optional) Maximum amount of data the host will accept in a TCP segment. Value is an int between `108` and `8860`. If not specified then the value would be the automatic calculated MSS value. ## Attributes Reference diff --git a/website/docs/r/policy_l2_vpn_service.html.markdown b/website/docs/r/policy_l2_vpn_service.html.markdown index 7e2f6e981..c230ffacb 100644 --- a/website/docs/r/policy_l2_vpn_service.html.markdown +++ b/website/docs/r/policy_l2_vpn_service.html.markdown @@ -32,7 +32,8 @@ The following arguments are supported: * `description` - (Optional) Description of the resource. * `tag` - (Optional) A list of scope + tag pairs to associate with this resource. * `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource. -* `locale_service_path` - (Required) Path of the locale service associated with the L2 VPN Service. +* `locale_service_path` - (Deprecated) Path of the locale service associated with the L2 VPN Service. +* `gateway_path` - (Optional) Path of gateway associated with the L2 VPN Service. Note that at least one of `gateway_path` and `locale_service_path` must be specified for the L2 VPN Service object. * `enable_hub` - (Optional) This property applies only in `SERVER` mode. If set to true, traffic from any client will be replicated to all other clients. If set to false, traffic received from clients is only replicated to the local VPN endpoint. Default is `true`. * `mode` - (Optional) Specify an L2VPN service mode as SERVER or CLIENT. Value is one of `SERVER`, `CLIENT`. Default is `SERVER`. * `encap_ip_pool` - (Optional) IP Pool to allocate local and peer endpoint IPs. Format is ipv4 CIDR block. diff --git a/website/docs/r/policy_l2_vpn_session.html.markdown b/website/docs/r/policy_l2_vpn_session.html.markdown index 9d92a1bb2..f232c3f64 100644 --- a/website/docs/r/policy_l2_vpn_session.html.markdown +++ b/website/docs/r/policy_l2_vpn_session.html.markdown @@ -17,7 +17,7 @@ This resource is applicable to NSX Policy Manager and VMC. resource "nsxt_policy_l2_vpn_session" "test" { display_name = "L2 VPN Session" description = "Terraform-provisioned L2 VPN Tunnel" - service_path = nsxt_policy_ipsec_vpn_service.test.path + service_path = nsxt_policy_l2_vpn_service.test.path transport_tunnels = [nsxt_policy_ipsec_vpn_session.ipsec_vpn_session_for_l2vpn.path] } ``` @@ -32,8 +32,8 @@ The following arguments are supported: * `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource. * `service_path` - (Required) The path of the L2 VPN service for the VPN session. * `transport_tunnels` - (Required) List of transport tunnels paths for redundancy. L2VPN supports only `AES_GCM_128` encryption algorithm for IPSec tunnel profile. -* `direction` - (Optional) The traffic direction apply to the MSS clamping. `BOTH` or `NONE`. Must be specified together with `max_segment_size`. -* `max_segment_size` - (Optional) Maximum amount of data the host will accept in a TCP segment. Value should be between `108` and `8860`. Must be specified together with `direction`. +* `direction` - (Optional) The traffic direction apply to the MSS clamping. `BOTH` or `NONE`. +* `max_segment_size` - (Optional) Maximum amount of data the host will accept in a TCP segment. Value should be between `108` and `8860`. If not specified then the value would be the automatic calculated MSS value. * `local_address` - (Optional) IP Address of the local tunnel port. This property only applies in `CLIENT` mode. * `peer_address` - (Optional) IP Address of the peer tunnel port. This property only applies in `CLIENT` mode. * `protocol` - (Optional) Encapsulation protocol used by the tunnel. `GRE` is the only supported value.