From faadcd7707a1a4cf210f02d09b5146c910093307 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Thu, 13 Jun 2024 13:44:52 +0300 Subject: [PATCH] VPC Groups implementation Signed-off-by: Kobi Samoray --- api/api_list.yaml | 7 + api/infra/domains/group.go | 27 ++++ nsxt/provider.go | 1 + nsxt/resource_nsxt_policy_group.go | 125 ++++++++++++------ nsxt/resource_nsxt_policy_group_test.go | 35 ++--- nsxt/resource_nsxt_vpc_group.go | 36 +++++ nsxt/resource_nsxt_vpc_group_test.go | 166 ++++++++++++++++++++++++ tools/api-wrapper-generator.py | 11 ++ website/docs/r/vpc_group.html.markdown | 5 + 9 files changed, 355 insertions(+), 58 deletions(-) create mode 100644 nsxt/resource_nsxt_vpc_group.go create mode 100644 nsxt/resource_nsxt_vpc_group_test.go create mode 100644 website/docs/r/vpc_group.html.markdown diff --git a/api/api_list.yaml b/api/api_list.yaml index 80cc82ba8..adf531ba6 100644 --- a/api/api_list.yaml +++ b/api/api_list.yaml @@ -242,6 +242,13 @@ - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model type: Multitenancy + - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs + model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model + type: VPC + ignore_params: + Delete: + - failIfSubtreeExistsParam + - forceParam model_name: Group obj_name: Group supported_method: diff --git a/api/infra/domains/group.go b/api/infra/domains/group.go index 6fad70aa3..dd1bff036 100644 --- a/api/infra/domains/group.go +++ b/api/infra/domains/group.go @@ -11,6 +11,7 @@ import ( client0 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains" model0 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" client2 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains" + client3 "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs" utl "github.com/vmware/terraform-provider-nsxt/api/utl" ) @@ -31,6 +32,9 @@ func NewGroupsClient(sessionContext utl.SessionContext, connector vapiProtocolCl case utl.Multitenancy: client = client2.NewGroupsClient(connector) + case utl.VPC: + client = client3.NewGroupsClient(connector) + default: return nil } @@ -67,6 +71,13 @@ func (c GroupClientContext) Get(domainIdParam string, groupIdParam string) (mode return obj, err } + case utl.VPC: + client := c.Client.(client3.GroupsClient) + obj, err = client.Get(utl.DefaultOrgID, c.ProjectID, c.VPCID, groupIdParam) + if err != nil { + return obj, err + } + default: return obj, errors.New("invalid infrastructure for model") } @@ -94,6 +105,10 @@ func (c GroupClientContext) Patch(domainIdParam string, groupIdParam string, gro client := c.Client.(client2.GroupsClient) err = client.Patch(utl.DefaultOrgID, c.ProjectID, domainIdParam, groupIdParam, groupParam) + case utl.VPC: + client := c.Client.(client3.GroupsClient) + err = client.Patch(utl.DefaultOrgID, c.ProjectID, c.VPCID, groupIdParam, groupParam) + default: err = errors.New("invalid infrastructure for model") } @@ -130,6 +145,10 @@ func (c GroupClientContext) Update(domainIdParam string, groupIdParam string, gr client := c.Client.(client2.GroupsClient) obj, err = client.Update(utl.DefaultOrgID, c.ProjectID, domainIdParam, groupIdParam, groupParam) + case utl.VPC: + client := c.Client.(client3.GroupsClient) + obj, err = client.Update(utl.DefaultOrgID, c.ProjectID, c.VPCID, groupIdParam, groupParam) + default: err = errors.New("invalid infrastructure for model") } @@ -153,6 +172,10 @@ func (c GroupClientContext) Delete(domainIdParam string, groupIdParam string, fa client := c.Client.(client2.GroupsClient) err = client.Delete(utl.DefaultOrgID, c.ProjectID, domainIdParam, groupIdParam, failIfSubtreeExistsParam, forceParam) + case utl.VPC: + client := c.Client.(client3.GroupsClient) + err = client.Delete(utl.DefaultOrgID, c.ProjectID, c.VPCID, groupIdParam) + default: err = errors.New("invalid infrastructure for model") } @@ -185,6 +208,10 @@ func (c GroupClientContext) List(domainIdParam string, cursorParam *string, incl client := c.Client.(client2.GroupsClient) obj, err = client.List(utl.DefaultOrgID, c.ProjectID, domainIdParam, cursorParam, includeMarkForDeleteObjectsParam, includedFieldsParam, memberTypesParam, pageSizeParam, sortAscendingParam, sortByParam) + case utl.VPC: + client := c.Client.(client3.GroupsClient) + obj, err = client.List(utl.DefaultOrgID, c.ProjectID, c.VPCID, cursorParam, includeMarkForDeleteObjectsParam, includedFieldsParam, memberTypesParam, pageSizeParam, sortAscendingParam, sortByParam) + default: err = errors.New("invalid infrastructure for model") } diff --git a/nsxt/provider.go b/nsxt/provider.go index c239f2ba4..219c61f93 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -497,6 +497,7 @@ func Provider() *schema.Provider { "nsxt_policy_compute_sub_cluster": resourceNsxtPolicyComputeSubCluster(), "nsxt_policy_tier0_inter_vrf_routing": resourceNsxtPolicyTier0InterVRFRouting(), "nsxt_vpc_security_policy": resourceNsxtVPCSecurityPolicy(), + "nsxt_vpc_group": resourceNsxtVPCGroup(), }, ConfigureFunc: providerConfigure, diff --git a/nsxt/resource_nsxt_policy_group.go b/nsxt/resource_nsxt_policy_group.go index e3859a6b6..a405d9eb0 100644 --- a/nsxt/resource_nsxt_policy_group.go +++ b/nsxt/resource_nsxt_policy_group.go @@ -94,42 +94,50 @@ func resourceNsxtPolicyGroup() *schema.Resource { State: nsxtDomainResourceImporter, }, - Schema: map[string]*schema.Schema{ - "nsx_id": getNsxIDSchema(), - "path": getPathSchema(), - "display_name": getDisplayNameSchema(), - "description": getDescriptionSchema(), - "revision": getRevisionSchema(), - "tag": getTagsSchema(), - "context": getContextSchema(false, false, false), - "domain": getDomainNameSchema(), - "group_type": { - Type: schema.TypeString, - Description: "Indicates the group type", - ValidateFunc: validation.StringInSlice(groupTypeValues, false), - Optional: true, - }, - "criteria": { - Type: schema.TypeList, - Description: "Criteria to determine Group membership", - Elem: getCriteriaSetSchema(), - Optional: true, - }, - "conjunction": { - Type: schema.TypeList, - Description: "A conjunction applied to 2 sets of criteria.", - Elem: getConjunctionSchema(), - Optional: true, - }, - "extended_criteria": { - Type: schema.TypeList, - Description: "Extended criteria to determine group membership. extended_criteria is implicitly \"AND\" with criteria", - Elem: getExtendedCriteriaSetSchema(), - Optional: true, - MaxItems: 1, - }, + Schema: getPolicyGroupSchema(true), + } +} + +func getPolicyGroupSchema(withDomain bool) map[string]*schema.Schema { + s := map[string]*schema.Schema{ + "nsx_id": getNsxIDSchema(), + "path": getPathSchema(), + "display_name": getDisplayNameSchema(), + "description": getDescriptionSchema(), + "revision": getRevisionSchema(), + "tag": getTagsSchema(), + "context": getContextSchema(false, false, !withDomain), + "group_type": { + Type: schema.TypeString, + Description: "Indicates the group type", + ValidateFunc: validation.StringInSlice(groupTypeValues, false), + Optional: true, + }, + "criteria": { + Type: schema.TypeList, + Description: "Criteria to determine Group membership", + Elem: getCriteriaSetSchema(), + Optional: true, + }, + "conjunction": { + Type: schema.TypeList, + Description: "A conjunction applied to 2 sets of criteria.", + Elem: getConjunctionSchema(), + Optional: true, + }, + "extended_criteria": { + Type: schema.TypeList, + Description: "Extended criteria to determine group membership. extended_criteria is implicitly \"AND\" with criteria", + Elem: getExtendedCriteriaSetSchema(), + Optional: true, + MaxItems: 1, }, } + + if withDomain { + s["domain"] = getDomainNameSchema() + } + return s } func getIPAddressExpressionSchema() *schema.Resource { @@ -833,10 +841,18 @@ func validateGroupCriteriaAndConjunctions(criteriaSets []interface{}, conjunctio } func resourceNsxtPolicyGroupCreate(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralCreate(d, m, true) +} + +func resourceNsxtPolicyGroupGeneralCreate(d *schema.ResourceData, m interface{}, withDomain bool) error { connector := getPolicyConnector(m) + domainName := "" + if withDomain { + domainName = d.Get("domain").(string) + } // Initialize resource Id and verify this ID is not yet used - id, err := getOrGenerateID2(d, m, resourceNsxtPolicyGroupExistsInDomainPartial(d.Get("domain").(string))) + id, err := getOrGenerateID2(d, m, resourceNsxtPolicyGroupExistsInDomainPartial(domainName)) if err != nil { return err } @@ -886,7 +902,7 @@ func resourceNsxtPolicyGroupCreate(d *schema.ResourceData, m interface{}) error if client == nil { return policyResourceNotSupportedError() } - err = client.Patch(d.Get("domain").(string), id, obj) + err = client.Patch(domainName, id, obj) // Create the resource using PATCH log.Printf("[INFO] Creating Group with ID %s", id) @@ -897,13 +913,20 @@ func resourceNsxtPolicyGroupCreate(d *schema.ResourceData, m interface{}) error d.SetId(id) d.Set("nsx_id", id) - return resourceNsxtPolicyGroupRead(d, m) + return resourceNsxtPolicyGroupGeneralRead(d, m, withDomain) } func resourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralRead(d, m, true) +} + +func resourceNsxtPolicyGroupGeneralRead(d *schema.ResourceData, m interface{}, withDomain bool) error { connector := getPolicyConnector(m) id := d.Id() - domainName := d.Get("domain").(string) + domainName := "" + if withDomain { + domainName = d.Get("domain").(string) + } if id == "" { return fmt.Errorf("Error obtaining Group ID") } @@ -920,7 +943,9 @@ func resourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error { setPolicyTagsInSchema(d, obj.Tags) d.Set("nsx_id", id) d.Set("path", obj.Path) - d.Set("domain", getDomainFromResourcePath(*obj.Path)) + if withDomain { + d.Set("domain", getDomainFromResourcePath(*obj.Path)) + } d.Set("revision", obj.Revision) groupType := "" if len(obj.GroupType) > 0 && util.NsxVersionHigherOrEqual("3.2.0") { @@ -951,6 +976,10 @@ func resourceNsxtPolicyGroupRead(d *schema.ResourceData, m interface{}) error { } func resourceNsxtPolicyGroupUpdate(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralUpdate(d, m, true) +} + +func resourceNsxtPolicyGroupGeneralUpdate(d *schema.ResourceData, m interface{}, withDomain bool) error { connector := getPolicyConnector(m) id := d.Id() @@ -1007,15 +1036,23 @@ func resourceNsxtPolicyGroupUpdate(d *schema.ResourceData, m interface{}) error } // Update the resource using PATCH - err = client.Patch(d.Get("domain").(string), id, obj) + domainName := "" + if withDomain { + domainName = d.Get("domain").(string) + } + err = client.Patch(domainName, id, obj) if err != nil { return handleUpdateError("Group", id, err) } - return resourceNsxtPolicyGroupRead(d, m) + return resourceNsxtPolicyGroupGeneralRead(d, m, withDomain) } func resourceNsxtPolicyGroupDelete(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralDelete(d, m, true) +} + +func resourceNsxtPolicyGroupGeneralDelete(d *schema.ResourceData, m interface{}, withDomain bool) error { id := d.Id() if id == "" { return fmt.Errorf("Error obtaining Group ID") @@ -1030,7 +1067,11 @@ func resourceNsxtPolicyGroupDelete(d *schema.ResourceData, m interface{}) error if client == nil { return policyResourceNotSupportedError() } - return client.Delete(d.Get("domain").(string), id, &failIfSubtreeExists, &forceDelete) + domainName := "" + if withDomain { + domainName = d.Get("domain").(string) + } + return client.Delete(domainName, id, &failIfSubtreeExists, &forceDelete) } err := doDelete() diff --git a/nsxt/resource_nsxt_policy_group_test.go b/nsxt/resource_nsxt_policy_group_test.go index f4ab7451e..f28160ffa 100644 --- a/nsxt/resource_nsxt_policy_group_test.go +++ b/nsxt/resource_nsxt_policy_group_test.go @@ -11,7 +11,8 @@ import ( func TestAccResourceNsxtPolicyGroup_basicImport(t *testing.T) { name := getAccTestResourceName() - testResourceName := "nsxt_policy_group.test" + resourceName := "nsxt_policy_group" + testResourceName := fmt.Sprintf("%s.test", resourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -21,7 +22,7 @@ func TestAccResourceNsxtPolicyGroup_basicImport(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyGroupIPAddressImportTemplate(name, false), + Config: testAccNsxtPolicyGroupIPAddressImportTemplate(name, resourceName, false), }, { ResourceName: testResourceName, @@ -34,7 +35,8 @@ func TestAccResourceNsxtPolicyGroup_basicImport(t *testing.T) { func TestAccResourceNsxtPolicyGroup_basicImport_multitenancy(t *testing.T) { name := getAccTestResourceName() - testResourceName := "nsxt_policy_group.test" + resourceName := "nsxt_policy_group" + testResourceName := fmt.Sprintf("%s.test", resourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccOnlyMultitenancy(t) }, @@ -44,7 +46,7 @@ func TestAccResourceNsxtPolicyGroup_basicImport_multitenancy(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyGroupIPAddressImportTemplate(name, true), + Config: testAccNsxtPolicyGroupIPAddressImportTemplate(name, resourceName, true), }, { ResourceName: testResourceName, @@ -71,7 +73,8 @@ func TestAccResourceNsxtPolicyGroup_addressCriteria_multitenancy(t *testing.T) { func testAccResourceNsxtPolicyGroupAddressCriteria(t *testing.T, withContext bool, preCheck func()) { name := getAccTestResourceName() - testResourceName := "nsxt_policy_group.test" + resourceName := "nsxt_policy_group" + testResourceName := fmt.Sprintf("%s.test", resourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: preCheck, @@ -81,7 +84,7 @@ func testAccResourceNsxtPolicyGroupAddressCriteria(t *testing.T, withContext boo }, Steps: []resource.TestStep{ { - Config: testAccNsxtPolicyGroupAddressCreateTemplate(name, withContext), + Config: testAccNsxtPolicyGroupAddressCreateTemplate(name, resourceName, withContext), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyGroupExists(testResourceName, defaultDomain), resource.TestCheckResourceAttr(testResourceName, "display_name", name), @@ -99,7 +102,7 @@ func testAccResourceNsxtPolicyGroupAddressCriteria(t *testing.T, withContext boo ), }, { - Config: testAccNsxtPolicyGroupAddressUpdateTemplate(name, withContext), + Config: testAccNsxtPolicyGroupAddressUpdateTemplate(name, resourceName, withContext), Check: resource.ComposeTestCheckFunc( testAccNsxtPolicyGroupExists(testResourceName, defaultDomain), resource.TestCheckResourceAttr(testResourceName, "display_name", name), @@ -718,27 +721,27 @@ func testAccNsxtPolicyGroupCheckDestroy(state *terraform.State, displayName stri return nil } -func testAccNsxtPolicyGroupIPAddressImportTemplate(name string, withContext bool) string { +func testAccNsxtPolicyGroupIPAddressImportTemplate(name string, resourceName string, withContext bool) string { context := "" if withContext { context = testAccNsxtPolicyMultitenancyContext() } return fmt.Sprintf(` -resource "nsxt_policy_group" "test" { +resource "%s" "test" { %s display_name = "%s" description = "Acceptance Test" } -`, context, name) +`, resourceName, context, name) } -func testAccNsxtPolicyGroupAddressCreateTemplate(name string, withContext bool) string { +func testAccNsxtPolicyGroupAddressCreateTemplate(name, resourceName string, withContext bool) string { context := "" if withContext { context = testAccNsxtPolicyMultitenancyContext() } return fmt.Sprintf(` -resource "nsxt_policy_group" "test" { +resource "%s" "test" { %s display_name = "%s" description = "Acceptance Test" @@ -769,16 +772,16 @@ resource "nsxt_policy_group" "test" { tag = "tag2" } } -`, context, name) +`, resourceName, context, name) } -func testAccNsxtPolicyGroupAddressUpdateTemplate(name string, withContext bool) string { +func testAccNsxtPolicyGroupAddressUpdateTemplate(name, resourceName string, withContext bool) string { context := "" if withContext { context = testAccNsxtPolicyMultitenancyContext() } return fmt.Sprintf(` -resource "nsxt_policy_group" "test" { +resource "%s" "test" { %s display_name = "%s" description = "Acceptance Test" @@ -789,7 +792,7 @@ resource "nsxt_policy_group" "test" { } } } -`, context, name) +`, resourceName, context, name) } func testAccNsxtGlobalPolicyGroupIPAddressCreateTemplate(name string, siteName string) string { diff --git a/nsxt/resource_nsxt_vpc_group.go b/nsxt/resource_nsxt_vpc_group.go new file mode 100644 index 000000000..6bdff0ac1 --- /dev/null +++ b/nsxt/resource_nsxt_vpc_group.go @@ -0,0 +1,36 @@ +/* Copyright © 2024 Broadcom, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func resourceNsxtVPCGroup() *schema.Resource { + return &schema.Resource{ + Create: resourceNsxtVPCGroupCreate, + Read: resourceNsxtVPCGroupRead, + Update: resourceNsxtVPCGroupUpdate, + Delete: resourceNsxtVPCGroupDelete, + Importer: &schema.ResourceImporter{ + State: nsxtPolicyPathResourceImporter, + }, + + Schema: getPolicyGroupSchema(false), + } +} + +func resourceNsxtVPCGroupCreate(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralCreate(d, m, false) +} + +func resourceNsxtVPCGroupRead(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralRead(d, m, false) +} + +func resourceNsxtVPCGroupUpdate(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralUpdate(d, m, false) +} + +func resourceNsxtVPCGroupDelete(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyGroupGeneralDelete(d, m, false) +} diff --git a/nsxt/resource_nsxt_vpc_group_test.go b/nsxt/resource_nsxt_vpc_group_test.go new file mode 100644 index 000000000..da9495363 --- /dev/null +++ b/nsxt/resource_nsxt_vpc_group_test.go @@ -0,0 +1,166 @@ +/* Copyright © 2024 Broadcom, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccResourceNsxtVPCGroup_basicImport(t *testing.T) { + name := getAccTestResourceName() + resourceName := "nsxt_vpc_group" + testResourceName := fmt.Sprintf("%s.test", resourceName) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccOnlyVPC(t) }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtVPCGroupCheckDestroy(state, name) + }, + Steps: []resource.TestStep{ + { + Config: testAccNsxtPolicyGroupIPAddressImportTemplate(name, resourceName, true), + }, + { + ResourceName: testResourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccResourceNsxtPolicyImportIDRetriever(testResourceName), + }, + }, + }) +} + +func TestAccResourceNsxtVPCGroup_addressCriteria(t *testing.T) { + name := getAccTestResourceName() + resourceName := "nsxt_vpc_group" + testResourceName := fmt.Sprintf("%s.test", resourceName) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccOnlyVPC(t) + }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtPolicyGroupCheckDestroy(state, name, defaultDomain) + }, + Steps: []resource.TestStep{ + { + Config: testAccNsxtVPCGroupAddressCreateTemplate(name, resourceName, true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyGroupExists(testResourceName, defaultDomain), + resource.TestCheckResourceAttr(testResourceName, "display_name", name), + resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "conjunction.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "2"), + resource.TestCheckResourceAttr(testResourceName, "criteria.#", "2"), + ), + }, + { + Config: testAccNsxtVPCGroupAddressUpdateTemplate(name, resourceName, true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyGroupExists(testResourceName, defaultDomain), + resource.TestCheckResourceAttr(testResourceName, "display_name", name), + resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "conjunction.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "criteria.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "criteria.0.ipaddress_expression.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "criteria.0.ipaddress_expression.0.ip_addresses.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "criteria.1.macaddress_expression.#", "0"), + ), + }, + }, + }) +} + +func testAccNsxtVPCGroupCheckDestroy(state *terraform.State, displayName string) error { + connector := getPolicyConnector(testAccProvider.Meta().(nsxtClients)) + + for _, rs := range state.RootModule().Resources { + + if rs.Type != "nsxt_vpc_group" { + continue + } + + resourceID := rs.Primary.Attributes["id"] + exists, err := resourceNsxtPolicyGroupExistsInDomain(testAccGetSessionContext(), resourceID, "", connector) + if err != nil { + return err + } + if exists { + return fmt.Errorf("policy Group %s still exists", displayName) + } + } + return nil +} + +func testAccNsxtVPCGroupAddressCreateTemplate(name, resourceName string, withContext bool) string { + context := "" + if withContext { + context = testAccNsxtPolicyMultitenancyContext() + } + return fmt.Sprintf(` +resource "%s" "test" { +%s + display_name = "%s" + description = "Acceptance Test" + + criteria { + ipaddress_expression { + ip_addresses = ["111.1.1.1", "222.2.2.2"] + } + } + + conjunction { + operator = "OR" + } + + criteria { + ipaddress_expression { + ip_addresses = ["122.1.1.1"] + } + } + + tag { + scope = "scope1" + tag = "tag1" + } + + tag { + scope = "scope2" + tag = "tag2" + } +} +`, resourceName, context, name) +} + +func testAccNsxtVPCGroupAddressUpdateTemplate(name, resourceName string, withContext bool) string { + context := "" + if withContext { + context = testAccNsxtPolicyMultitenancyContext() + } + return fmt.Sprintf(` +resource "%s" "test" { +%s + display_name = "%s" + description = "Acceptance Test" + + criteria { + ipaddress_expression { + ip_addresses = ["122.1.1.1"] + } + } +} +`, resourceName, context, name) +} diff --git a/tools/api-wrapper-generator.py b/tools/api-wrapper-generator.py index eae9fa9a7..6f64837b6 100644 --- a/tools/api-wrapper-generator.py +++ b/tools/api-wrapper-generator.py @@ -71,6 +71,12 @@ def new_func_call_setup(api, subs_dict): return '%s(%s)' % (g[0], ', '.join(arg_list)) +def find_api_package_attributes(api, type): + for a in api['api_packages']: + if type == a['type']: + return a + + def api_func_call_setup(api, subs_dict): g = parse_api_call(subs_dict['func_def']) arg_list = get_arglist(g[2]) @@ -79,6 +85,11 @@ def api_func_call_setup(api, subs_dict): elif subs_dict['type'] == "VPC": arg_list = ['utl.DefaultOrgID', 'c.ProjectID', 'c.VPCID'] + arg_list arg_list.remove('domainIdParam') + attrs = find_api_package_attributes(api, subs_dict['type']) + x = attrs.get('ignore_params', {}) + for n in attrs.get('ignore_params', {}).get(g[1], []): + arg_list.remove(n) + return '%s(%s)' % (g[1], ', '.join(arg_list)) diff --git a/website/docs/r/vpc_group.html.markdown b/website/docs/r/vpc_group.html.markdown new file mode 100644 index 000000000..62a0de5e1 --- /dev/null +++ b/website/docs/r/vpc_group.html.markdown @@ -0,0 +1,5 @@ +--- +subcategory: "VPC" +layout: "nsxt" +page_title: "NSXT: nsxt_vpc_group" +description: A resource to configure a VPC Group and its members.