Skip to content

Commit

Permalink
VPC E-W security policy resource
Browse files Browse the repository at this point in the history
Add VPC support to the API wrapper generator and implement the resource
for east-west VPC security policy.

Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed May 28, 2024
1 parent 5308952 commit 6f3a00f
Show file tree
Hide file tree
Showing 81 changed files with 375 additions and 189 deletions.
4 changes: 3 additions & 1 deletion api/api_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@
- 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
model_name: SecurityPolicy
obj_name: SecurityPolicy
client_name: SecurityPoliciesClient
Expand Down Expand Up @@ -986,7 +989,6 @@
- New
- Get
- Delete
- List
- Patch
- Update
- List
Expand Down
27 changes: 27 additions & 0 deletions api/infra/domains/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -31,6 +32,9 @@ func NewSecurityPoliciesClient(sessionContext utl.SessionContext, connector vapi
case utl.Multitenancy:
client = client2.NewSecurityPoliciesClient(connector)

case utl.VPC:
client = client3.NewSecurityPoliciesClient(connector)

default:
return nil
}
Expand Down Expand Up @@ -67,6 +71,13 @@ func (c SecurityPolicyClientContext) Get(domainIdParam string, securityPolicyIdP
return obj, err
}

case utl.VPC:
client := c.Client.(client3.SecurityPoliciesClient)
obj, err = client.Get(utl.DefaultOrgID, c.ProjectID, c.VPCID, securityPolicyIdParam)
if err != nil {
return obj, err
}

default:
return obj, errors.New("invalid infrastructure for model")
}
Expand Down Expand Up @@ -94,6 +105,10 @@ func (c SecurityPolicyClientContext) Patch(domainIdParam string, securityPolicyI
client := c.Client.(client2.SecurityPoliciesClient)
err = client.Patch(utl.DefaultOrgID, c.ProjectID, domainIdParam, securityPolicyIdParam, securityPolicyParam)

case utl.VPC:
client := c.Client.(client3.SecurityPoliciesClient)
err = client.Patch(utl.DefaultOrgID, c.ProjectID, c.VPCID, securityPolicyIdParam, securityPolicyParam)

default:
err = errors.New("invalid infrastructure for model")
}
Expand Down Expand Up @@ -130,6 +145,10 @@ func (c SecurityPolicyClientContext) Update(domainIdParam string, securityPolicy
client := c.Client.(client2.SecurityPoliciesClient)
obj, err = client.Update(utl.DefaultOrgID, c.ProjectID, domainIdParam, securityPolicyIdParam, securityPolicyParam)

case utl.VPC:
client := c.Client.(client3.SecurityPoliciesClient)
obj, err = client.Update(utl.DefaultOrgID, c.ProjectID, c.VPCID, securityPolicyIdParam, securityPolicyParam)

default:
err = errors.New("invalid infrastructure for model")
}
Expand All @@ -153,6 +172,10 @@ func (c SecurityPolicyClientContext) Delete(domainIdParam string, securityPolicy
client := c.Client.(client2.SecurityPoliciesClient)
err = client.Delete(utl.DefaultOrgID, c.ProjectID, domainIdParam, securityPolicyIdParam)

case utl.VPC:
client := c.Client.(client3.SecurityPoliciesClient)
err = client.Delete(utl.DefaultOrgID, c.ProjectID, c.VPCID, securityPolicyIdParam)

default:
err = errors.New("invalid infrastructure for model")
}
Expand Down Expand Up @@ -185,6 +208,10 @@ func (c SecurityPolicyClientContext) List(domainIdParam string, cursorParam *str
client := c.Client.(client2.SecurityPoliciesClient)
obj, err = client.List(utl.DefaultOrgID, c.ProjectID, domainIdParam, cursorParam, includeMarkForDeleteObjectsParam, includeRuleCountParam, includedFieldsParam, pageSizeParam, sortAscendingParam, sortByParam)

case utl.VPC:
client := c.Client.(client3.SecurityPoliciesClient)
obj, err = client.List(utl.DefaultOrgID, c.ProjectID, c.VPCID, cursorParam, includeMarkForDeleteObjectsParam, includeRuleCountParam, includedFieldsParam, pageSizeParam, sortAscendingParam, sortByParam)

default:
err = errors.New("invalid infrastructure for model")
}
Expand Down
3 changes: 3 additions & 0 deletions api/utl/api_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ const (
Global = 0
Local = 1
Multitenancy = 2
VPC = 3
)

type SessionContext struct {
ClientType ClientType
ProjectID string
VPCID string
}
type ClientContext struct {
Client interface{}
ClientType ClientType
ProjectID string
VPCID string
}

func ConvertModelBindingType(obj interface{}, sourceType bindings.BindingType, destType bindings.BindingType) (interface{}, error) {
Expand Down
2 changes: 2 additions & 0 deletions api/utl_file_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
type SessionContext struct {
ClientType ClientType
ProjectID string
VPCID string
}
type ClientContext struct {
Client interface{}
ClientType ClientType
ProjectID string
VPCID string
}

func ConvertModelBindingType(obj interface{}, sourceType bindings.BindingType, destType bindings.BindingType) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_context_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ data "nsxt_policy_context_profile" "test" {
}

func testAccNsxtPolicyContextProfileMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtPolicyContext()
return fmt.Sprintf(`
resource "nsxt_policy_context_profile" "test" {
%s
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_dhcp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func testAccDataSourceNsxtPolicyDhcpServerBasic(t *testing.T, withContext bool,
func testAccNsxtPolicyDhcpServerReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
resource "nsxt_policy_dhcp_server" "test" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestAccDataSourceNsxtPolicyGatewayLocaleService_multitenancy(t *testing.T)
func testAccNsxtPolicyGatewayLocaleServiceTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_edge_cluster" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_gateway_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func testAccDataSourceNsxtPolicyGatewayPolicyBasic(t *testing.T, withContext boo
func testAccNsxtPolicyGatewayPolicyTemplate(name string, category string, extra string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}

return fmt.Sprintf(`
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_gateway_qos_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func testAccDataSourceNsxtPolicyGatewayQosProfileDeleteByName(name string) error
func testAccNsxtPolicyGatewayQosProfileReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_gateway_qos_profile" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func testAccDataSourceNsxtPolicyGroupDeleteByName(domain string, name string) er
func testAccNsxtPolicyGroupReadTemplate(domain string, name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_group" "test" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func testAccDataSourceNsxtPolicyIntrusionServiceProfileBasic(t *testing.T, withC
func testAccNsxtPolicyIntrusionServiceProfileReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_intrusion_service_profile" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ip_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func testAccDataSourceNsxtPolicyIPBlockDeleteByName(name string) error {
func testAccNsxtPolicyIPBlockReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_ip_block" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ip_discovery_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data "nsxt_policy_ip_discovery_profile" "test" {
}

func testAccNsxtPolicyIPDiscoveryProfileMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtPolicyContext()
return fmt.Sprintf(`
resource "nsxt_policy_ip_discovery_profile" "test" {
%s
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ip_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func testAccDataSourceNsxtPolicyIPPoolDeleteByName(name string) error {
func testAccNsxtPolicyIPPoolReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_ip_pool" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ipv6_dad_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func testAccDataSourceNsxtPolicyIpv6DadProfileDeleteByName(name string) error {
func testAccNsxtPolicyIpv6DadProfileReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_ipv6_dad_profile" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ipv6_ndra_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func testAccDataSourceNsxtPolicyIpv6NdraProfileDeleteByName(name string) error {
func testAccNsxtPolicyIpv6NdraProfileReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_ipv6_ndra_profile" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_mac_discovery_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ data "nsxt_policy_mac_discovery_profile" "test" {
}

func testAccNsxtPolicyMacDiscoveryProfileMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtPolicyContext()
return fmt.Sprintf(`
resource "nsxt_policy_mac_discovery_profile" "test" {
%s
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_qos_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func testAccDataSourceNsxtPolicyQosProfileDeleteByName(name string) error {
func testAccNsxtPolicyQosProfileReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_qos_profile" "test" {
Expand Down
6 changes: 3 additions & 3 deletions nsxt/data_source_nsxt_policy_realization_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ data "nsxt_policy_realization_info" "realization_info" {
func testAccNsxtPolicyRealizationInfoReadDataSourceErrorTemplate(withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
resource "nsxt_policy_ip_pool" "test" {
Expand Down Expand Up @@ -260,7 +260,7 @@ data "nsxt_policy_realization_info" "realization_info" {
func testAccNsxtPolicyRealizationInfoReadDataSourceTemplate(resourceDataType string, resourceName string, entityType string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "%s" "policy_resource" {
Expand All @@ -278,7 +278,7 @@ data "nsxt_policy_realization_info" "realization_info" {
func testAccNsxtPolicyRealizationInfoReadResourceTemplate(resourceType string, resourceName string, entityType string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
resource "%s" "policy_resource" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestAccDataSourceNsxtPolicySecurityPolicy_default(t *testing.T) {
func testAccNsxtPolicySecurityPolicyTemplate(name string, category string, extra string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
resource "nsxt_policy_security_policy" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_segment_realization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func testAccNsxtPolicySegmentRealizationTemplate(vlan, withContext bool) string
extra := ""
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
if vlan {
resource = "nsxt_policy_vlan_segment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data "nsxt_policy_segment_security_profile" "test" {
}

func testAccNsxtPolicySegmentSecurityProfileMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtPolicyContext()
return fmt.Sprintf(`
resource "nsxt_policy_segment_security_profile" "test" {
%s
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func testAccDataSourceNsxtPolicySegmentDeleteByName(name string) error {
func testAccNsxtPolicySegmentReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_segment" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ data "nsxt_policy_service" "test" {
}

func testAccNsxtPolicyServiceMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtPolicyContext()
return fmt.Sprintf(`
resource "nsxt_policy_service" "test" {
%s
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_spoofguard_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data "nsxt_policy_spoofguard_profile" "test" {
}

func testAccNsxtPolicySpoofGuardProfileMultitenancyTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtPolicyContext()
return fmt.Sprintf(`
resource "nsxt_policy_spoof_guard_profile" "test" {
%s
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_tier1_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func testAccDataSourceNsxtPolicyTier1GatewayDeleteByName(routerName string) erro
func testAccNsxtPolicyTier1ReadTemplate(name string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_tier1_gateway" "test" {
Expand Down
4 changes: 2 additions & 2 deletions nsxt/data_source_nsxt_policy_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func testAccDataSourceNsxtPolicyVMBasic(t *testing.T, withContext bool, preCheck
func testAccNsxtPolicyVMReadByNameTemplate(withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_vm" "test" {
Expand All @@ -73,7 +73,7 @@ data "nsxt_policy_vm" "test" {
func testAccNsxtPolicyVMReadByIDTemplate(withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_vm" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestAccDataSourceNsxtPolicyVMs_filter(t *testing.T) {
func testAccNsxtPolicyVMsTemplate(valueType string, withContext bool) string {
context := ""
if withContext {
context = testAccNsxtPolicyMultitenancyContext()
context = testAccNsxtPolicyContext()
}
return fmt.Sprintf(`
data "nsxt_policy_vms" "test" {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_policy_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func testAccDataSourceNsxtPolicyVPCDeleteByName(name string) error {
}

func testAccNsxtPolicyVPCReadTemplate(name string) string {
context := testAccNsxtPolicyMultitenancyContext()
context := testAccNsxtPolicyContext()
return fmt.Sprintf(`
data "nsxt_policy_ip_block" "test" {
%s
Expand Down
Loading

0 comments on commit 6f3a00f

Please sign in to comment.