Skip to content

Commit

Permalink
Feat/v4 pbrs on v4 networks (#13)
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

* tests and docs for pbrs

* change module  name from v4 to v2

* change package  name to networkingv2

* add pbr_v2 example

* fix import

---------

Co-authored-by: Abhishek <[email protected]>
  • Loading branch information
Haroon-Dweikat-Ntx and abhimutant authored Sep 6, 2024
1 parent 518378f commit 4ff3f14
Show file tree
Hide file tree
Showing 18 changed files with 2,929 additions and 9 deletions.
118 changes: 118 additions & 0 deletions examples/pbr_v2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
terraform{
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "1.6.0"
}
}
}

#defining nutanix configuration
provider "nutanix"{
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = 9440
insecure = true
}

# create PBR with vpc name with any source or destination or protocol with permit action

resource "nutanix_pbr_v2" "pbr1" {
name = "%[1]s"
description = "%[2]s"
vpc_ext_id = var.vpc_reference_uuid
priority = 14
policies{
policy_match{
source{
address_type = "ANY"
}
destination{
address_type = "ANY"
}
protocol_type = "UDP"
}
policy_action{
action_type = "PERMIT"
}
}
}



# create PBR with vpc uuid with source external

resource "nutanix_pbr_v2" "pbr2" {
name = "%[1]s"
description = "%[2]s"
vpc_ext_id = var.vpc_reference_uuid
priority = 11
policies{
policy_match{
source{
address_type = "EXTERNAL"
}
destination{
address_type = "SUBNET"
subnet_prefix{
ipv4{
ip{
value= "10.10.10.0"
prefix_length = 24
}
}
}
}
protocol_type = "ANY"
}
policy_action{
action_type = "FORWARD"
nexthop_ip_address{
ipv4{
value = "10.10.10.10"
}
}
}
}
}


#create PBR with vpc name with source Any and destination external
resource "nutanix_pbr_v2" "pbr3" {
name = "%[1]s"
description = "%[2]s"
vpc_ext_id = var.vpc_reference_uuid
priority = 14
policies{
policy_match{
source{
address_type = "ALL"
}
destination{
address_type = "INTERNET"
}
protocol_type = "UDP"
}
policy_action{
action_type = "PERMIT"
}
}
}

# list pbr

data "nutanix_pbrs_v2" "pbr4" {
}



# get an entity with pbr uuid

data "nutanix_pbr_v2" "pbr5" {
ext_id = resource.nutanix_pbr_v2.rtest.ext_id
depends_on = [
resource.nutanix_pbr_v2.rtest
]
}

6 changes: 6 additions & 0 deletions examples/pbr_v2/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "password"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
vpc_reference_uuid = "<vpc_uuid>"
17 changes: 17 additions & 0 deletions examples/pbr_v2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#define the type of variables to be used in terraform file
variable "nutanix_username" {
type = string
}
variable "nutanix_password" {
type = string
}
variable "nutanix_endpoint" {
type = string
}
variable "nutanix_port" {
type = string
}

variable "vpc_reference_uuid" {
type = string
}
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_pbr_v2": networkingv2.DatasourceNutanixPbrV2(),
"nutanix_pbrs_v2": networkingv2.DatasourceNutanixPbrsV2(),
},
ResourcesMap: map[string]*schema.Resource{
"nutanix_virtual_machine": prism.ResourceNutanixVirtualMachine(),
Expand Down Expand Up @@ -279,6 +281,7 @@ func Provider() *schema.Provider {
"nutanix_subnet_v2": networkingv2.ResourceNutanixSubnetV2(),
"nutanix_floating_ip_v2": networkingv2.ResourceNutanixFloatingIPv2(),
"nutanix_vpc_v2": networkingv2.ResourceNutanixVPCsV2(),
"nutanix_pbr_v2": networkingv2.ResourceNutanixPbrsV2(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down
2 changes: 2 additions & 0 deletions nutanix/sdks/v4/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

type Client struct {
RoutingPolicy *api.RoutingPoliciesApi
SubnetAPIInstance *api.SubnetsApi
VpcAPIInstance *api.VpcsApi
FloatingIPAPIInstance *api.FloatingIpsApi
Expand All @@ -29,6 +30,7 @@ func NewNetworkingClient(credentials client.Credentials) (*Client, error) {
}

f := &Client{
RoutingPolicy: api.NewRoutingPoliciesApi(baseClient),
SubnetAPIInstance: api.NewSubnetsApi(baseClient),
VpcAPIInstance: api.NewVpcsApi(baseClient),
FloatingIPAPIInstance: api.NewFloatingIpsApi(baseClient),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func testAccFipDataSourceConfig(name, desc string) string {
data "nutanix_clusters" "clusters" {}
locals {
cluster0 = data.nutanix_clusters.clusters.entities[0].metadata.uuid
cluster0 = data.nutanix_clusters.clusters.entities[0].metadata.uuid
}
resource "nutanix_subnet_v2" "test" {
Expand Down
Loading

0 comments on commit 4ff3f14

Please sign in to comment.