From 9cb33ee8ce53d5eec4b2bf1ba0909e09f723b945 Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 13 Feb 2023 11:19:06 +0100 Subject: [PATCH 1/9] Adding support for Nested Services Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service.go | 63 +++++++++++++++++++++ website/docs/r/policy_service.html.markdown | 3 + 2 files changed, 66 insertions(+) diff --git a/nsxt/resource_nsxt_policy_service.go b/nsxt/resource_nsxt_policy_service.go index 6b2b47036..5d36294c6 100644 --- a/nsxt/resource_nsxt_policy_service.go +++ b/nsxt/resource_nsxt_policy_service.go @@ -184,6 +184,23 @@ func resourceNsxtPolicyService() *schema.Resource { }, }, }, + + "nested_service_entry": { + Type: schema.TypeSet, + Description: "Nested service service entry", + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "display_name": getOptionalDisplayNameSchema(false), + "description": getDescriptionSchema(), + "nested_service_path": { + Type: schema.TypeString, + Description: "Path of the nested service", + Required: true, + }, + }, + }, + }, }, } } @@ -377,6 +394,34 @@ func resourceNsxtPolicyServiceGetEntriesFromSchema(d *schema.ResourceData) ([]*d serviceEntries = append(serviceEntries, entryStruct) } + // Nested Service service entries + nestedEntries := d.Get("nested_service_entry").(*schema.Set).List() + for _, nestedEntry := range nestedEntries { + entryData := nestedEntry.(map[string]interface{}) + displayName := entryData["display_name"].(string) + description := entryData["description"].(string) + nested_service_path := entryData["nested_service_path"].(string) + + // Use a different random Id each time + id := newUUID() + + serviceEntry := model.NestedServiceServiceEntry{ + Id: &id, + DisplayName: &displayName, + Description: &description, + NestedServicePath: &nested_service_path, + ResourceType: model.ServiceEntry_RESOURCE_TYPE_NESTEDSERVICESERVICEENTRY, + } + + dataValue, errs := converter.ConvertToVapi(serviceEntry, model.NestedServiceServiceEntryBindingType()) // To define + if errs != nil { + return serviceEntries, errs[0] + } + entryStruct := dataValue.(*data.StructValue) + serviceEntries = append(serviceEntries, entryStruct) + + } + return serviceEntries, nil } @@ -500,6 +545,7 @@ func resourceNsxtPolicyServiceRead(d *schema.ResourceData, m interface{}) error var etherEntriesList []map[string]interface{} var ipProtEntriesList []map[string]interface{} var algEntriesList []map[string]interface{} + var nestedServiceEntriesList []map[string]interface{} for _, entry := range obj.ServiceEntries { elem := make(map[string]interface{}) @@ -588,6 +634,18 @@ func resourceNsxtPolicyServiceRead(d *schema.ResourceData, m interface{}) error elem["display_name"] = filterServiceEntryDisplayName(*serviceEntry.DisplayName, *serviceEntry.Id) elem["description"] = serviceEntry.Description igmpEntriesList = append(igmpEntriesList, elem) + } else if resourceType == model.ServiceEntry_RESOURCE_TYPE_NESTEDSERVICESERVICEENTRY { + nestedEntry, errs := converter.ConvertToGolang(entry, model.NestedServiceServiceEntryBindingType()) + if errs != nil { + return errs[0] + } + + serviceEntry := nestedEntry.(model.NestedServiceServiceEntry) + elem["display_name"] = filterServiceEntryDisplayName(*serviceEntry.DisplayName, *serviceEntry.Id) + elem["description"] = serviceEntry.Description + elem["nested_service_path"] = serviceEntry.NestedServicePath + nestedServiceEntriesList = append(nestedServiceEntriesList, elem) + } else { return fmt.Errorf("Unrecognized Service Entry Type %s", resourceType) } @@ -623,6 +681,11 @@ func resourceNsxtPolicyServiceRead(d *schema.ResourceData, m interface{}) error return err } + err = d.Set("nested_service_entry", nestedServiceEntriesList) + if err != nil { + return err + } + return nil } diff --git a/website/docs/r/policy_service.html.markdown b/website/docs/r/policy_service.html.markdown index e2d594e00..0040fce7b 100644 --- a/website/docs/r/policy_service.html.markdown +++ b/website/docs/r/policy_service.html.markdown @@ -90,6 +90,9 @@ The service must contain at least 1 entry (of at least one of the types), and po * `destination_port` - (Required) a single destination port. * `source_ports` - (Optional) Set of source ports/ranges. * `algorithm` - (Required) Algorithm, one of `ORACLE_TNS`, `FTP`, `SUN_RPC_TCP`, `SUN_RPC_UDP`, `MS_RPC_TCP`, `MS_RPC_UDP`, `NBNS_BROADCAST`(Deprecated), `NBDG_BROADCAST`(Deprecated), `TFTP`. +* `nested_service_entry` - (Optional) Set of Nested service entries. Each with the following attributes: + * `nested_service_path` - (Required) Path of the nested service. + ## Attributes Reference From 0af55786b1f97376c2697907650f24d3b8fe0de6 Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 13 Feb 2023 14:06:24 +0100 Subject: [PATCH 2/9] Removing forgotten comment Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nsxt/resource_nsxt_policy_service.go b/nsxt/resource_nsxt_policy_service.go index 5d36294c6..d9f902e8d 100644 --- a/nsxt/resource_nsxt_policy_service.go +++ b/nsxt/resource_nsxt_policy_service.go @@ -413,7 +413,7 @@ func resourceNsxtPolicyServiceGetEntriesFromSchema(d *schema.ResourceData) ([]*d ResourceType: model.ServiceEntry_RESOURCE_TYPE_NESTEDSERVICESERVICEENTRY, } - dataValue, errs := converter.ConvertToVapi(serviceEntry, model.NestedServiceServiceEntryBindingType()) // To define + dataValue, errs := converter.ConvertToVapi(serviceEntry, model.NestedServiceServiceEntryBindingType()) if errs != nil { return serviceEntries, errs[0] } From 1337ed2246cf49be746e5f444a1dabf1fb03d04e Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 20 Feb 2023 08:46:51 +0100 Subject: [PATCH 3/9] Resolving comment #1 Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/nsxt/resource_nsxt_policy_service.go b/nsxt/resource_nsxt_policy_service.go index d9f902e8d..c217a7798 100644 --- a/nsxt/resource_nsxt_policy_service.go +++ b/nsxt/resource_nsxt_policy_service.go @@ -193,11 +193,7 @@ func resourceNsxtPolicyService() *schema.Resource { Schema: map[string]*schema.Schema{ "display_name": getOptionalDisplayNameSchema(false), "description": getDescriptionSchema(), - "nested_service_path": { - Type: schema.TypeString, - Description: "Path of the nested service", - Required: true, - }, + "service_path": getPolicyPathSchema(true, false, "Nested Service Path"), }, }, }, From d7aff153a5ea4d09d5986a07520e5e0061856a91 Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 20 Feb 2023 08:48:43 +0100 Subject: [PATCH 4/9] Resolving linter warning Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nsxt/resource_nsxt_policy_service.go b/nsxt/resource_nsxt_policy_service.go index c217a7798..d18d096d7 100644 --- a/nsxt/resource_nsxt_policy_service.go +++ b/nsxt/resource_nsxt_policy_service.go @@ -396,7 +396,7 @@ func resourceNsxtPolicyServiceGetEntriesFromSchema(d *schema.ResourceData) ([]*d entryData := nestedEntry.(map[string]interface{}) displayName := entryData["display_name"].(string) description := entryData["description"].(string) - nested_service_path := entryData["nested_service_path"].(string) + nestedServicePath := entryData["nested_service_path"].(string) // Use a different random Id each time id := newUUID() @@ -405,7 +405,7 @@ func resourceNsxtPolicyServiceGetEntriesFromSchema(d *schema.ResourceData) ([]*d Id: &id, DisplayName: &displayName, Description: &description, - NestedServicePath: &nested_service_path, + NestedServicePath: &nestedServicePath, ResourceType: model.ServiceEntry_RESOURCE_TYPE_NESTEDSERVICESERVICEENTRY, } From 808b08b59df39eef0e29ced100f577061efb2993 Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 20 Feb 2023 09:24:10 +0100 Subject: [PATCH 5/9] Resolving comment #2 Signed-off-by: Axel Francois --- website/docs/r/policy_service.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/r/policy_service.html.markdown b/website/docs/r/policy_service.html.markdown index 0040fce7b..6de394ec6 100644 --- a/website/docs/r/policy_service.html.markdown +++ b/website/docs/r/policy_service.html.markdown @@ -90,7 +90,9 @@ The service must contain at least 1 entry (of at least one of the types), and po * `destination_port` - (Required) a single destination port. * `source_ports` - (Optional) Set of source ports/ranges. * `algorithm` - (Required) Algorithm, one of `ORACLE_TNS`, `FTP`, `SUN_RPC_TCP`, `SUN_RPC_UDP`, `MS_RPC_TCP`, `MS_RPC_UDP`, `NBNS_BROADCAST`(Deprecated), `NBDG_BROADCAST`(Deprecated), `TFTP`. -* `nested_service_entry` - (Optional) Set of Nested service entries. Each with the following attributes: +* `nested_service_entry` - (Optional) Feature intruduced since at least NSX-T 3.1, set of Nested service entries. Each with the following attributes: + * `display_name` - (Optional) Display name of the service entry. + * `description` - (Optional) Description of the service entry. * `nested_service_path` - (Required) Path of the nested service. From f9fbaaf591499cff1de2f2bedf51637cf77dacce Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 20 Feb 2023 14:24:08 +0100 Subject: [PATCH 6/9] Bugfix : wrong name is schema Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nsxt/resource_nsxt_policy_service.go b/nsxt/resource_nsxt_policy_service.go index d18d096d7..746bc9f61 100644 --- a/nsxt/resource_nsxt_policy_service.go +++ b/nsxt/resource_nsxt_policy_service.go @@ -191,9 +191,9 @@ func resourceNsxtPolicyService() *schema.Resource { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "display_name": getOptionalDisplayNameSchema(false), - "description": getDescriptionSchema(), - "service_path": getPolicyPathSchema(true, false, "Nested Service Path"), + "display_name": getOptionalDisplayNameSchema(false), + "description": getDescriptionSchema(), + "nested_service_path": getPolicyPathSchema(true, false, "Nested Service Path"), }, }, }, From ab07065244a5ab83c84aeec804804cb24e88b5b9 Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 20 Feb 2023 14:49:28 +0100 Subject: [PATCH 7/9] Adding tests Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service_test.go | 181 ++++++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/nsxt/resource_nsxt_policy_service_test.go b/nsxt/resource_nsxt_policy_service_test.go index e93ef3666..bc917c5ef 100644 --- a/nsxt/resource_nsxt_policy_service_test.go +++ b/nsxt/resource_nsxt_policy_service_test.go @@ -575,6 +575,118 @@ func TestAccResourceNsxtPolicyService_algType(t *testing.T) { }) } +func TestAccResourceNsxtPolicyService_nestedServiceType(t *testing.T) { + name := getAccTestResourceName() + updateName := getAccTestResourceName() + testResourceName := "nsxt_policy_service.test" + testNestedService1Name := "HTTP" + testNestedService2Name := "HTTPS" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtPolicyServiceCheckDestroy(state, updateName) + }, + Steps: []resource.TestStep{ + { + // Step 0: Create a nested service + Config: testAccNsxtPolicyNestedServiceCreateTemplate(name, testNestedService1Name), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyServiceExists(testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", name), + resource.TestCheckResourceAttr(testResourceName, "description", "Nested service"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "algorithm_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "l4_port_set_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "icmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "igmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ether_type_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ip_protocol_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + ), + }, + { + // Step 1: Add another nested service + Config: testAccNsxtPolicyNestedServiceUpdateTemplate(name, testNestedService1Name, testNestedService2Name), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyServiceExists(testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", name), + resource.TestCheckResourceAttr(testResourceName, "description", "Nested service"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "algorithm_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "l4_port_set_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "icmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "igmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ether_type_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ip_protocol_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "2"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.1.display_name", testNestedService2Name), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.1.description", "Entry-2"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.1.nested_service_path", "/infra/services/"+testNestedService2Name), + ), + }, + { + // Step 2: Remove nested service 2 + Config: testAccNsxtPolicyNestedServiceCreateTemplate(name, testNestedService1Name), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyServiceExists(testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", name), + resource.TestCheckResourceAttr(testResourceName, "description", "Nested service"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "algorithm_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "l4_port_set_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "icmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "igmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ether_type_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ip_protocol_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + ), + }, + { + // Step 3: Mix with other service types + Config: testAccNsxtPolicyNestedServiceMixedTemplate(name, testNestedService1Name), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyServiceExists(testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", name), + resource.TestCheckResourceAttr(testResourceName, "description", "Nested service"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "algorithm_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "l4_port_set_entry.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "l4_port_set_entry.0.display_name", "entry-2"), + resource.TestCheckResourceAttr(testResourceName, "l4_port_set_entry.0.description", "Entry-2"), + resource.TestCheckResourceAttr(testResourceName, "l4_port_set_entry.0.protocol", "TCP"), + resource.TestCheckResourceAttr(testResourceName, "icmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "igmp_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ether_type_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "ip_protocol_entry.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), + resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + ), + }, + }, + }) +} + func TestAccResourceNsxtPolicyService_importBasic(t *testing.T) { name := getAccTestResourceName() testResourceName := "nsxt_policy_service.test" @@ -921,3 +1033,72 @@ resource "nsxt_policy_service" "test" { } }`, serviceName, serviceName, alg, sourcePorts, destPort) } + +func testAccNsxtPolicyNestedServiceCreateTemplate(serviceName string, nestedServiceEntryName string) string { + return fmt.Sprintf(` +resource "nsxt_policy_service" "test" { + description = "Nested service" + display_name = "%s" + + nested_service_entry { + display_name = "%s" + description = "Entry-1" + nested_service_path = "/infra/services/%s" + } + + tag { + scope = "scope1" + tag = "tag1" + } +}`, serviceName, nestedServiceEntryName, nestedServiceEntryName) +} + +func testAccNsxtPolicyNestedServiceUpdateTemplate(serviceName string, nestedServiceEntry1Name string, nestedServiceEntry2Name string) string { + return fmt.Sprintf(`resource "nsxt_policy_service" "test" { + description = "Nested service" + display_name = "%s" + + nested_service_entry { + display_name = "%s" + description = "Entry-1" + nested_service_path = "/infra/services/%s" + } + + nested_service_entry { + display_name = "%s" + description = "Entry-2" + nested_service_path = "/infra/services/%s" + } + + tag { + scope = "scope1" + tag = "tag1" + } +}`, serviceName, nestedServiceEntry1Name, nestedServiceEntry1Name, nestedServiceEntry2Name, nestedServiceEntry2Name) + +} + +func testAccNsxtPolicyNestedServiceMixedTemplate(serviceName string, nestedServiceEntryName string) string { + return fmt.Sprintf(`resource "nsxt_policy_service" "test" { + description = "Nested service" + display_name = "%s" + + nested_service_entry { + display_name = "%s" + description = "Entry-1" + nested_service_path = "/infra/services/%s" + } + + l4_port_set_entry { + display_name = "entry-2" + description = "Entry-2" + protocol = "TCP" + destination_ports = [ "443" ] + } + + tag { + scope = "scope1" + tag = "tag1" + } +}`, serviceName, nestedServiceEntryName, nestedServiceEntryName) +} From 0af0086b34de2938026092d483ef4ea89b54e65f Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Mon, 27 Feb 2023 10:27:00 +0100 Subject: [PATCH 8/9] Resolving comment #3 Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/nsxt/resource_nsxt_policy_service_test.go b/nsxt/resource_nsxt_policy_service_test.go index bc917c5ef..270fde5c3 100644 --- a/nsxt/resource_nsxt_policy_service_test.go +++ b/nsxt/resource_nsxt_policy_service_test.go @@ -5,6 +5,7 @@ package nsxt import ( "fmt" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -581,6 +582,17 @@ func TestAccResourceNsxtPolicyService_nestedServiceType(t *testing.T) { testResourceName := "nsxt_policy_service.test" testNestedService1Name := "HTTP" testNestedService2Name := "HTTPS" + regexpService1Name, err := regexp.Compile("/.*/" + testNestedService1Name) + + if err != nil { + fmt.Printf("Error while compiling regexp: %v", err) + } + + regexpService2Name, err := regexp.Compile("/.*/" + testNestedService2Name) + + if err != nil { + fmt.Printf("Error while compiling regexp: %v", err) + } resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -608,7 +620,7 @@ func TestAccResourceNsxtPolicyService_nestedServiceType(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "1"), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), - resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + resource.TestMatchResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", regexpService1Name), ), }, { @@ -630,10 +642,10 @@ func TestAccResourceNsxtPolicyService_nestedServiceType(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "2"), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), - resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + resource.TestMatchResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", regexpService1Name), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.1.display_name", testNestedService2Name), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.1.description", "Entry-2"), - resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.1.nested_service_path", "/infra/services/"+testNestedService2Name), + resource.TestMatchResourceAttr(testResourceName, "nested_service_entry.1.nested_service_path", regexpService2Name), ), }, { @@ -655,7 +667,7 @@ func TestAccResourceNsxtPolicyService_nestedServiceType(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "1"), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), - resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + resource.TestMatchResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", regexpService1Name), ), }, { @@ -680,7 +692,7 @@ func TestAccResourceNsxtPolicyService_nestedServiceType(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.#", "1"), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.display_name", testNestedService1Name), resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.description", "Entry-1"), - resource.TestCheckResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", "/infra/services/"+testNestedService1Name), + resource.TestMatchResourceAttr(testResourceName, "nested_service_entry.0.nested_service_path", regexpService1Name), ), }, }, From ca1a03ff6c84f03261b2b00ac304d1083fd40849 Mon Sep 17 00:00:00 2001 From: Axel Francois Date: Wed, 1 Mar 2023 09:23:53 +0100 Subject: [PATCH 9/9] Fix web linter and comment #4 Signed-off-by: Axel Francois --- nsxt/resource_nsxt_policy_service_test.go | 14 +++++++------- website/docs/r/policy_service.html.markdown | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nsxt/resource_nsxt_policy_service_test.go b/nsxt/resource_nsxt_policy_service_test.go index 270fde5c3..b6a9e58bc 100644 --- a/nsxt/resource_nsxt_policy_service_test.go +++ b/nsxt/resource_nsxt_policy_service_test.go @@ -1055,14 +1055,14 @@ resource "nsxt_policy_service" "test" { nested_service_entry { display_name = "%s" description = "Entry-1" - nested_service_path = "/infra/services/%s" + nested_service_path = "%s" } tag { scope = "scope1" tag = "tag1" } -}`, serviceName, nestedServiceEntryName, nestedServiceEntryName) +}`, serviceName, nestedServiceEntryName, testAccAdjustPolicyInfraConfig("/infra/services/"+nestedServiceEntryName)) } func testAccNsxtPolicyNestedServiceUpdateTemplate(serviceName string, nestedServiceEntry1Name string, nestedServiceEntry2Name string) string { @@ -1073,20 +1073,20 @@ func testAccNsxtPolicyNestedServiceUpdateTemplate(serviceName string, nestedServ nested_service_entry { display_name = "%s" description = "Entry-1" - nested_service_path = "/infra/services/%s" + nested_service_path = "%s" } nested_service_entry { display_name = "%s" description = "Entry-2" - nested_service_path = "/infra/services/%s" + nested_service_path = "%s" } tag { scope = "scope1" tag = "tag1" } -}`, serviceName, nestedServiceEntry1Name, nestedServiceEntry1Name, nestedServiceEntry2Name, nestedServiceEntry2Name) +}`, serviceName, nestedServiceEntry1Name, testAccAdjustPolicyInfraConfig("/infra/services/"+nestedServiceEntry1Name), nestedServiceEntry2Name, testAccAdjustPolicyInfraConfig("/infra/services/"+nestedServiceEntry2Name)) } @@ -1098,7 +1098,7 @@ func testAccNsxtPolicyNestedServiceMixedTemplate(serviceName string, nestedServi nested_service_entry { display_name = "%s" description = "Entry-1" - nested_service_path = "/infra/services/%s" + nested_service_path = "%s" } l4_port_set_entry { @@ -1112,5 +1112,5 @@ func testAccNsxtPolicyNestedServiceMixedTemplate(serviceName string, nestedServi scope = "scope1" tag = "tag1" } -}`, serviceName, nestedServiceEntryName, nestedServiceEntryName) +}`, serviceName, nestedServiceEntryName, testAccAdjustPolicyInfraConfig("/infra/services/"+nestedServiceEntryName)) } diff --git a/website/docs/r/policy_service.html.markdown b/website/docs/r/policy_service.html.markdown index 6de394ec6..e69c1445d 100644 --- a/website/docs/r/policy_service.html.markdown +++ b/website/docs/r/policy_service.html.markdown @@ -90,7 +90,7 @@ The service must contain at least 1 entry (of at least one of the types), and po * `destination_port` - (Required) a single destination port. * `source_ports` - (Optional) Set of source ports/ranges. * `algorithm` - (Required) Algorithm, one of `ORACLE_TNS`, `FTP`, `SUN_RPC_TCP`, `SUN_RPC_UDP`, `MS_RPC_TCP`, `MS_RPC_UDP`, `NBNS_BROADCAST`(Deprecated), `NBDG_BROADCAST`(Deprecated), `TFTP`. -* `nested_service_entry` - (Optional) Feature intruduced since at least NSX-T 3.1, set of Nested service entries. Each with the following attributes: +* `nested_service_entry` - (Optional) Feature introduced since at least NSX-T 3.1, set of Nested service entries. Each with the following attributes: * `display_name` - (Optional) Display name of the service entry. * `description` - (Optional) Description of the service entry. * `nested_service_path` - (Required) Path of the nested service.