Skip to content

Commit

Permalink
Feat/v4 network security rules on v4 networks (#15)
Browse files Browse the repository at this point in the history
* datasource for pbrs

* lint fixes. go error (gomnd, gosimple, golint)

* go checks, magic numbers(gomnd)

* fix config testcase as base client will differ in sdks

* datasourc for route tables

* resource for static route

* address groups v4

* service groups

* resource for service groups

* crud for service groups

* CRUD for address groups

* data source for network security

* CRUD for network security

* tests and docs for pbrs

* docs for route table

* docs for static route

* lint fixes

* testcases for address groups

* fixing lint issues

* lint fix

* docs for address groups

* test and docs for service groups

* docs and tcs for NSP

* resource tests for NSP

* tcs for NSP

* remove other services

* change module name from v4 to v2

* change package name to networkingv2

---------

Co-authored-by: Abhishek <[email protected]>
  • Loading branch information
Haroon-Dweikat-Ntx and abhimutant authored Sep 6, 2024
1 parent 1a966d9 commit 18a3a68
Show file tree
Hide file tree
Showing 17 changed files with 2,822 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/mitchellh/gox v1.0.1
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-beta.1
// github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.8.0-5295 // indirect
//github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v4.0.2-beta.1
github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v16.9.0-8634
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v16.9.0-8634 h1:my6PO/SXWtNqmMAVN2jkQULhK+4UoL1AsTEWW1ENsPY=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v16.9.0-8634/go.mod h1:vHyQVF3IKxmip+xGxXDQznKk1ffrVa4HSiEEueiekaE=
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-beta.1 h1:YpWpFBiRGrVEBgHKaHVb4PDtApjwl988X91EEftIvjk=
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-beta.1/go.mod h1:75Ro+aFIepNAkf2eWjFrFR7m+Ct36EVrD9n9pwAYBrc=
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.2-beta.1 h1:PvZQwYhhJtxmzLpnzEhHTpp2fV6woc6W65PHGsHzVfs=
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.2-beta.1/go.mod h1:+eZgV1+xL/r84qmuFSVt5R8OFRO70rEz92jOnVgJNco=
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1 h1:hvy3QCc2SgVidYxTq0rRPOazJOt1PP8A86kW7j6sywU=
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1/go.mod h1:Yhk+xD4mN90OKEHnk5ARf97CX5p4+MEC/B/YIVoZeZ0=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
Expand Down
7 changes: 7 additions & 0 deletions nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v3/karbon"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/microseg"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/networking"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/prism"

Expand Down Expand Up @@ -89,6 +90,10 @@ func (c *Config) Client() (*Client, error) {
if err != nil {
return nil, err
}
microsegClient, err := microseg.NewMicrosegClient(configCreds)
if err != nil {
return nil, err
}
return &Client{
WaitTimeout: c.WaitTimeout,
API: v3Client,
Expand All @@ -98,6 +103,7 @@ func (c *Config) Client() (*Client, error) {
Era: eraClient,
NetworkingAPI: networkingClient,
PrismAPI: prismClient,
MicroSegAPI: microsegClient,
}, nil
}

Expand All @@ -111,4 +117,5 @@ type Client struct {
Era *era.Client
NetworkingAPI *networking.Client
PrismAPI *prism.Client
MicroSegAPI *microseg.Client
}
3 changes: 3 additions & 0 deletions nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ func Provider() *schema.Provider {
"nutanix_vpcs_v2": networkingv2.DataSourceNutanixVPCsv2(),
"nutanix_floating_ip_v2": networkingv2.DatasourceNutanixFloatingIPV2(),
"nutanix_floating_ips_v2": networkingv2.DatasourceNutanixFloatingIPsV2(),
"nutanix_network_security_policy_v2": networkingv2.DataSourceNutanixNetworkSecurityPolicyV2(),
"nutanix_network_security_policies_v2": networkingv2.DataSourceNutanixNetworkSecurityPoliciesV2(),
"nutanix_route_table_v2": networkingv2.DatasourceNutanixRouteTableV2(),
"nutanix_route_tables_v2": networkingv2.DatasourceNutanixRouteTablesV2(),
"nutanix_pbr_v2": networkingv2.DatasourceNutanixPbrV2(),
Expand Down Expand Up @@ -283,6 +285,7 @@ func Provider() *schema.Provider {
"nutanix_subnet_v2": networkingv2.ResourceNutanixSubnetV2(),
"nutanix_floating_ip_v2": networkingv2.ResourceNutanixFloatingIPv2(),
"nutanix_vpc_v2": networkingv2.ResourceNutanixVPCsV2(),
"nutanix_network_security_policy_v2": networkingv2.ResourceNutanixNetworkSecurityPolicyV2(),
"nutanix_route_table_v2": networkingv2.ResourceNutanixRouteTablesV2(),
"nutanix_pbr_v2": networkingv2.ResourceNutanixPbrsV2(),
},
Expand Down
38 changes: 38 additions & 0 deletions nutanix/sdks/v4/microseg/microseg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package microseg

import (
"github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/api"
microseg "github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4/client"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

type Client struct {
AddressGroupAPIInstance *api.AddressGroupsApi
ServiceGroupAPIInstance *api.ServiceGroupsApi
NetworkingSecurityInstance *api.NetworkSecurityPoliciesApi
}

func NewMicrosegClient(credentials client.Credentials) (*Client, error) {
var baseClient *microseg.ApiClient

// check if all required fields are present. Else create an empty client
if credentials.Username != "" && credentials.Password != "" && credentials.Endpoint != "" {
pcClient := microseg.NewApiClient()

pcClient.Host = credentials.Endpoint
pcClient.Password = credentials.Password
pcClient.Username = credentials.Username
pcClient.Port = 9440
pcClient.VerifySSL = false

baseClient = pcClient
}

f := &Client{
AddressGroupAPIInstance: api.NewAddressGroupsApi(baseClient),
ServiceGroupAPIInstance: api.NewServiceGroupsApi(baseClient),
NetworkingSecurityInstance: api.NewNetworkSecurityPoliciesApi(baseClient),
}

return f, nil
}
Loading

0 comments on commit 18a3a68

Please sign in to comment.