Skip to content

Commit

Permalink
Release v3.5.2 (#39)
Browse files Browse the repository at this point in the history
New Features:

- Added possibility to use interfaces by IDs in the `netris_vnet` resource
  • Loading branch information
pogossian authored Sep 24, 2024
1 parent 94ef6ed commit 47f07c4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=registry.terraform.io
NAMESPACE=netrisai
NAME=netris
BINARY=terraform-provider-${NAME}
VERSION=3.5.0
VERSION=3.5.2
OS_ARCH=darwin_arm64
WORKDIRECTORY=examples

Expand Down
6 changes: 5 additions & 1 deletion docs/resources/vnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ resource "netris_vnet" "my-vnet" {
interface {
name = "swp7@my-sw02"
}
interface {
id = netris_lag.lag1-switch-01.id
}
}
depends_on = [
netris_switch.my-sw01,
Expand Down Expand Up @@ -104,6 +107,7 @@ Optional:

Optional:

- **name** (String) Network interface name. Example: `swp5@my-sw01`
- **id** (Number) Network interface ID. Example: `data.netris_network_interface.swp5-my-sw91.id`. Can't be used together `name`.
- **name** (String) Network interface name. Example: `swp5@my-sw01`. Can't be used together `id`.
- **vlanid** (String) VLAN tag for the current interface. Cannot be used together with global `vlanid`. If the main `vlanid` is also not set - means untagged. (Only for Netris Switch Fabric)
- **untagged** (String) This option is applicable only when a global `vlanid` is set. In such cases, the default value is `yes`. The valid value is `yes` or `no`. (Applicable exclusively to Netris Switch Fabric)
3 changes: 3 additions & 0 deletions examples/vnet_example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ resource "netris_vnet" "my-vnet" {
interface {
name = "swp8@my-switch02"
}
interface {
id = netris_lag.lag2-mc.id
}
}
depends_on = [
netris_switch.my-switch01,
Expand Down
53 changes: 47 additions & 6 deletions netris/vnet/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func Resource() *schema.Resource {
Description: "Block of interfaces",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Optional: true,
Description: "Switch port ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -112,6 +117,11 @@ func Resource() *schema.Resource {
Description: "Block of ports",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Optional: true,
Description: "Switch port ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -287,6 +297,7 @@ func resourceCreate(d *schema.ResourceData, m interface{}) error {
}
members = append(members, vnet.VNetAddPort{
AccessMode: accessMode,
ID: port["id"].(int),
Name: port["name"].(string),
Vlan: vID,
State: "active",
Expand All @@ -313,6 +324,7 @@ func resourceCreate(d *schema.ResourceData, m interface{}) error {
}
members = append(members, vnet.VNetAddPort{
AccessMode: accessMode,
ID: port["id"].(int),
Name: port["name"].(string),
Vlan: vID,
State: "active",
Expand Down Expand Up @@ -431,8 +443,10 @@ func resourceRead(d *schema.ResourceData, m interface{}) error {
}

tportVlanIDMap := make(map[string]string)
tportPortID := make(map[int]string)

tPorts := make(map[string]map[string]interface{})
tPortsId := make(map[int]map[string]interface{})
interfaces := false
gatewayMap := make(map[string]map[string]interface{})

Expand All @@ -451,14 +465,22 @@ func resourceRead(d *schema.ResourceData, m interface{}) error {
for _, p := range ports {
port := p.(map[string]interface{})
tportVlanIDMap[port["name"].(string)] = port["vlanid"].(string)
tportPortID[port["id"].(int)] = port["vlanid"].(string)
tPorts[port["name"].(string)] = port
if port["id"].(int) != 0 {
tPortsId[port["id"].(int)] = port
}
}
} else if p, ok := site["ports"]; ok {
ports := p.(*schema.Set).List()
for _, p := range ports {
port := p.(map[string]interface{})
tportVlanIDMap[port["name"].(string)] = port["vlanid"].(string)
tportPortID[port["id"].(int)] = port["vlanid"].(string)
tPorts[port["name"].(string)] = port
if port["id"].(int) != 0 {
tPortsId[port["id"].(int)] = port
}
}
}
}
Expand All @@ -473,18 +495,35 @@ func resourceRead(d *schema.ResourceData, m interface{}) error {
m := make(map[string]interface{})
name := fmt.Sprintf("%s@%s", port.Port, port.SwitchName)
if vlanFromTf, ok := tportVlanIDMap[name]; ok {
m["name"] = name
if vlanFromTf == "1" && vnetresp.Vlan != 0 && d.Get("vlanid").(string) != "" {
port.Vlan = "1"
}
}
m["name"] = name
if vlanFromTfId, ok := tportPortID[port.ID]; ok {
m["id"] = port.ID
if vlanFromTfId == "1" && vnetresp.Vlan != 0 && d.Get("vlanid").(string) != "" {
port.Vlan = "1"
}
}
m["vlanid"] = port.Vlan
m["lacp"] = "off"
if tPortUntagged := tPorts[name]["untagged"]; tPortUntagged != "" {
if port.Untagged {
m["untagged"] = "yes"
} else {
m["untagged"] = "no"
if tPort, exists := tPorts[name]; exists {
if tPortUntagged, ok := tPort["untagged"]; ok && tPortUntagged != "" {
if port.Untagged {
m["untagged"] = "yes"
} else {
m["untagged"] = "no"
}
}
}
if tPortid, exists := tPortsId[port.ID]; exists {
if tPortUntagged, ok := tPortid["untagged"]; ok && tPortUntagged != "" {
if port.Untagged {
m["untagged"] = "yes"
} else {
m["untagged"] = "no"
}
}
}
portList = append(portList, m)
Expand Down Expand Up @@ -667,6 +706,7 @@ func resourceUpdate(d *schema.ResourceData, m interface{}) error {
members = append(members, vnet.VNetUpdatePort{
AccessMode: accessMode,
Name: port["name"].(string),
ID: port["id"].(int),
Vlan: vID,
State: "active",
})
Expand Down Expand Up @@ -707,6 +747,7 @@ func resourceUpdate(d *schema.ResourceData, m interface{}) error {
members = append(members, vnet.VNetUpdatePort{
AccessMode: accessMode,
Name: port["name"].(string),
ID: port["id"].(int),
Vlan: vID,
State: "active",
})
Expand Down

0 comments on commit 47f07c4

Please sign in to comment.