Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/m overlay subnet #460

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client/v3/v3_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,11 @@ type SubnetResources struct {
VlanID *int64 `json:"vlan_id,omitempty" mapstructure:"vlan_id,omitempty"`

VswitchName *string `json:"vswitch_name,omitempty" mapstructure:"vswitch_name,omitempty"`

VPCReference *Reference `json:"vpc_reference,omitempty" mapstructure:"vpc_reference,omitempty"`

IsExternal *bool `json:"is_external,omitempty" mapstructure:"is_external,omitempty"`
EnableNAT *bool `json:"enable_nat,omitempty" mapstructure:"enable_nat,omitempty"`
}

// Subnet An intentful representation of a subnet spec
Expand Down Expand Up @@ -772,6 +777,10 @@ type SubnetResourcesDefStatus struct {
VlanID *int64 `json:"vlan_id,omitempty" mapstructure:"vlan_id,omitempty"`

VswitchName *string `json:"vswitch_name,omitempty" mapstructure:"vswitch_name,omitempty"`

VPCReference *Reference `json:"vpc_reference,omitempty" mapstructure:"vpc_reference,omitempty"`
IsExternal *bool `json:"is_external,omitempty" mapstructure:"is_external,omitempty"`
EnableNAT *bool `json:"enable_nat,omitempty" mapstructure:"enable_nat,omitempty"`
}

// SubnetDefStatus An intentful representation of a subnet status
Expand Down
74 changes: 74 additions & 0 deletions examples/external_subnets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
terraform {
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "1.6.0"
}
}
}
provider "nutanix" {
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
insecure = true
port = 9440
}

# pull all clusters
data "nutanix_clusters" "clusters" {}

# create local variable pointing to desired cluster
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

# External Subnets with NAT

resource "nutanix_subnet" "accNat" {
# General Info
name = "test-ext-sub-with-nat"
description = "Description of my test VLAN updated"

# subnet_type should be VLAN for external subnet with NAT
subnet_type = "VLAN"
cluster_uuid = local.cluster1
vlan_id = 121
subnet_ip = "10.xx.xx.xx"
default_gateway_ip = "10.xx.xx.xx"
prefix_length = 24

# required to be set true for external connectivity
is_external = true
# set true if NAT reuired
enable_nat = true

ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]

}

# External Subnet with No NAT

resource "nutanix_subnet" "accNoNat" {
# General Info
name = "test-ext-sub-with-no-nat"
description = "Description of my test VLAN updated"

# subnet_type should be VLAN for external subnet with No NAT
subnet_type = "VLAN"
cluster_uuid = local.cluster1
vlan_id = 121
subnet_ip = "10.xx.xx.xx"
default_gateway_ip = "10.xx.xx.xx"
prefix_length = 24

# required to be set true for external connectivity
is_external = true
# set fasle for No NAT
enable_nat = false

ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]

}
4 changes: 4 additions & 0 deletions examples/external_subnets/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "password"
nutanix_endpoint = "10.xx.xx.xx"
10 changes: 10 additions & 0 deletions examples/external_subnets/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#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
}
114 changes: 114 additions & 0 deletions examples/overlay_subnets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
terraform {
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "1.6.0"
}
}
}
provider "nutanix" {
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
insecure = true
port = 9440
}

# pull all clusters
data "nutanix_clusters" "clusters" {}

# create local variable pointing to desired cluster
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}


# overlay subnet resource

resource "nutanix_subnet" "acc" {
# General Information
name = "test-overlay-subnet"
description = "Description of my overlay subnet"

# subnet type should be overlay
subnet_type = "OVERLAY"
subnet_ip = "10.xx.xx.xx"
default_gateway_ip = "10.xx.xx.xx"
prefix_length = 24

dhcp_options = {
domain_name = "lab.fr"
tftp_server_name = "tftp.lab.fr"
boot_file_name = "pxelinux.0"
}

ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]

# vpc reference uuid is required for overlay subnet type
vpc_reference_uuid = var.vpc_reference_uuid

}

output "accSub"{
value = resource.nutanix_subnet.acc
}


# create a new overlay subnet with vpc and external subnet

# pull all clusters
data "nutanix_clusters" "clusters" {}

locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

# create external subnet
resource "nutanix_subnet" "sub-ext" {
cluster_uuid = local.cluster1
name = "test-ext-subnet"
description = "Description of my unit test VLAN"
vlan_id = 434
subnet_type = "VLAN"
subnet_ip = "10.xx.xx.xx"
default_gateway_ip = "10.xx.xx.xx"
ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]

prefix_length = 24
is_external = true
enable_nat = false
}

# create vpc with external subnet reference
resource "nutanix_vpc" "acctest-managed-vpc" {
name = "test-vpc"
external_subnet_reference_uuid = [
resource.nutanix_subnet.sub-ext.id
]
common_domain_name_server_ip_list{
ip = "x.x.x.x"
}
externally_routable_prefix_list{
ip= "xx.xx.xx.xx"
prefix_length= 16
}
}


# create overlay subnet with vpc reference
resource "nutanix_subnet" "acctest-managed" {
name = "test-overlay-subnet"
description = "Description of my unit test OVERLAY"
vpc_reference_uuid = resource.nutanix_vpc.acctest-managed-vpc.id
subnet_type = "OVERLAY"
subnet_ip = "10.xx.xx.xx"
default_gateway_ip = "10.xx.xx.xx"
ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]
prefix_length = 24
}
5 changes: 5 additions & 0 deletions examples/overlay_subnets/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "password"
nutanix_endpoint = "10.xx.xx.xx"
vpc_reference_uuid = "<vpc_uuid>"
13 changes: 13 additions & 0 deletions examples/overlay_subnets/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#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 "vpc_reference_uuid" {
type = string
}
18 changes: 18 additions & 0 deletions nutanix/data_source_nutanix_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ func dataSourceNutanixSubnet() *schema.Resource {
Type: schema.TypeString,
},
},
"vpc_reference": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"is_external": {
Type: schema.TypeBool,
Computed: true,
},
"enable_nat": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -342,6 +357,9 @@ func dataSourceNutanixSubnetRead(ctx context.Context, d *schema.ResourceData, me
d.Set("dhcp_server_address_port", port)
d.Set("vlan_id", utils.Int64Value(resp.Status.Resources.VlanID))
d.Set("network_function_chain_reference", flattenReferenceValues(resp.Status.Resources.NetworkFunctionChainReference))
d.Set("vpc_reference", flattenReferenceValues(resp.Status.Resources.VPCReference))
d.Set("is_external", resp.Status.Resources.IsExternal)
d.Set("enable_nat", resp.Status.Resources.EnableNAT)

d.SetId(utils.StringValue(resp.Metadata.UUID))

Expand Down
19 changes: 18 additions & 1 deletion nutanix/data_source_nutanix_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ func dataSourceNutanixSubnets() *schema.Resource {
Type: schema.TypeString,
},
},
"vpc_reference": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"is_external": {
Type: schema.TypeBool,
Computed: true,
},
"enable_nat": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -318,7 +333,9 @@ func dataSourceNutanixSubnetsRead(ctx context.Context, d *schema.ResourceData, m
entity["dhcp_server_address_port"] = port
entity["vlan_id"] = utils.Int64Value(v.Status.Resources.VlanID)
entity["network_function_chain_reference"] = flattenReferenceValues(v.Status.Resources.NetworkFunctionChainReference)

entity["vpc_reference"] = flattenReferenceValues(v.Status.Resources.VPCReference)
entity["is_external"] = v.Status.Resources.IsExternal
entity["enable_nat"] = v.Status.Resources.EnableNAT
entities[k] = entity
}

Expand Down
Loading