From 69b85ec66eabcf35293d71f9fe7f9e0f1dac41c3 Mon Sep 17 00:00:00 2001 From: Pierre Lafievre Date: Wed, 3 Jul 2024 15:35:14 +0200 Subject: [PATCH] B #515: fix ignored vlan_id --- CHANGELOG.md | 6 ++++++ .../resource_opennebula_virtual_network.go | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce34a423..78eabda93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.4.2 (Unreleased) + +BUG FIXES: + +* resources/opennebula_virtual_network: allow to set a `vlan_id` for ovswitch (#515) + # 1.4.1 (Unreleased) FEATURES: diff --git a/opennebula/resource_opennebula_virtual_network.go b/opennebula/resource_opennebula_virtual_network.go index 309b588e1..1faff5773 100644 --- a/opennebula/resource_opennebula_virtual_network.go +++ b/opennebula/resource_opennebula_virtual_network.go @@ -802,15 +802,19 @@ func generateVn(d *schema.ResourceData) (string, error) { tpl.Add(vnk.Name, vnname) tpl.Add(vnk.VNMad, vnmad) - if mandatoryVLAN(vnmad) { - if d.Get("automatic_vlan_id") == true { - tpl.Add("AUTOMATIC_VLAN_ID", "YES") - } else if vlanid, ok := d.GetOk("vlan_id"); ok { - tpl.Add(vnk.VlanID, vlanid.(string)) - } else { - return "", fmt.Errorf("You must specify a 'vlan_id' or set the flag 'automatic_vlan_id'") - } + vlanSet := false + if d.Get("automatic_vlan_id").(bool) { + tpl.Add("AUTOMATIC_VLAN_ID", "YES") + vlanSet = true + } else if vlanid, ok := d.GetOk("vlan_id"); ok { + tpl.Add(vnk.VlanID, vlanid.(string)) + vlanSet = true + } + + if mandatoryVLAN(vnmad) && !vlanSet { + return "", fmt.Errorf("you must specify a 'vlan_id' or set the flag 'automatic_vlan_id'") } + if vnbridge, ok := d.GetOk("bridge"); ok { tpl.Add(vnk.Bridge, vnbridge.(string)) }