Skip to content

Commit

Permalink
Merge pull request #196 from megaport/fix/ordered-vlan-state
Browse files Browse the repository at this point in the history
fix: change state of ordered_vlan when updating to prevent unintended null ordered_vlan
  • Loading branch information
MegaportPhilipBrowne authored Dec 10, 2024
2 parents ace031b + a168341 commit 350830d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/provider/vxc_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3338,24 +3338,24 @@ func (r *vxcResource) Update(ctx context.Context, req resource.UpdateRequest, re
// If Ordered VLAN is different from actual VLAN, attempt to change it to the ordered VLAN value.
if !aEndPlan.OrderedVLAN.IsUnknown() && !aEndPlan.OrderedVLAN.IsNull() && !aEndPlan.OrderedVLAN.Equal(aEndState.VLAN) {
updateReq.AEndVLAN = megaport.PtrTo(int(aEndPlan.OrderedVLAN.ValueInt64()))
aEndState.OrderedVLAN = aEndPlan.OrderedVLAN
}
aEndState.OrderedVLAN = aEndPlan.OrderedVLAN

if !aEndPlan.InnerVLAN.IsUnknown() && !aEndPlan.InnerVLAN.IsNull() && !aEndPlan.InnerVLAN.Equal(aEndState.InnerVLAN) {
updateReq.AEndInnerVLAN = megaport.PtrTo(int(aEndPlan.InnerVLAN.ValueInt64()))
aEndState.InnerVLAN = aEndPlan.InnerVLAN
}
aEndState.InnerVLAN = aEndPlan.InnerVLAN

// If Ordered VLAN is different from actual VLAN, attempt to change it to the ordered VLAN value.
if !bEndPlan.OrderedVLAN.IsUnknown() && !bEndPlan.OrderedVLAN.IsNull() && !bEndPlan.OrderedVLAN.Equal(bEndState.VLAN) {
updateReq.BEndVLAN = megaport.PtrTo(int(bEndPlan.OrderedVLAN.ValueInt64()))
bEndState.OrderedVLAN = bEndPlan.OrderedVLAN
}
bEndState.OrderedVLAN = bEndPlan.OrderedVLAN

if !bEndPlan.InnerVLAN.IsUnknown() && !bEndPlan.InnerVLAN.IsNull() && !bEndPlan.InnerVLAN.Equal(bEndState.InnerVLAN) {
updateReq.BEndInnerVLAN = megaport.PtrTo(int(bEndPlan.InnerVLAN.ValueInt64()))
bEndState.InnerVLAN = bEndPlan.InnerVLAN
}
bEndState.InnerVLAN = bEndPlan.InnerVLAN

if !plan.RateLimit.IsNull() && !plan.RateLimit.Equal(state.RateLimit) {
updateReq.RateLimit = megaport.PtrTo(int(plan.RateLimit.ValueInt64()))
Expand Down
54 changes: 54 additions & 0 deletions internal/provider/vxc_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,60 @@ func (suite *VXCBasicProviderTestSuite) TestAccMegaportVXC_BasicUntagVLAN() {
},
ImportStateVerifyIgnore: []string{"last_updated", "a_end_partner_config", "b_end_partner_config", "a_end", "b_end", "contract_start_date", "contract_end_date", "live_date", "resources", "provisioning_status"},
},
{
Config: providerConfig + fmt.Sprintf(`
data "megaport_location" "loc" {
name = "%s"
}
resource "megaport_port" "port_1" {
product_name = "%s"
port_speed = 1000
location_id = data.megaport_location.loc.id
contract_term_months = 12
marketplace_visibility = false
}
resource "megaport_port" "port_2" {
product_name = "%s"
port_speed = 1000
location_id = data.megaport_location.loc.id
contract_term_months = 12
marketplace_visibility = false
}
resource "megaport_vxc" "vxc" {
product_name = "%s"
rate_limit = 500
contract_term_months = 12
cost_centre = "%s"
a_end = {
requested_product_uid = megaport_port.port_1.product_uid
}
b_end = {
requested_product_uid = megaport_port.port_2.product_uid
}
}
`, VXCLocationOne, portName1, portName2, vxcName, costCentreName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("megaport_port.port_1", "product_name", portName1),
resource.TestCheckResourceAttr("megaport_port.port_1", "port_speed", "1000"),
resource.TestCheckResourceAttr("megaport_port.port_1", "contract_term_months", "12"),
resource.TestCheckResourceAttr("megaport_port.port_1", "marketplace_visibility", "false"),
resource.TestCheckResourceAttrSet("megaport_port.port_1", "product_uid"),
resource.TestCheckResourceAttr("megaport_port.port_2", "product_name", portName2),
resource.TestCheckResourceAttr("megaport_port.port_2", "port_speed", "1000"),
resource.TestCheckResourceAttr("megaport_port.port_2", "contract_term_months", "12"),
resource.TestCheckResourceAttr("megaport_port.port_2", "marketplace_visibility", "false"),
resource.TestCheckResourceAttrSet("megaport_port.port_2", "product_uid"),
resource.TestCheckResourceAttr("megaport_vxc.vxc", "product_name", vxcName),
resource.TestCheckResourceAttr("megaport_vxc.vxc", "rate_limit", "500"),
resource.TestCheckResourceAttr("megaport_vxc.vxc", "contract_term_months", "12"),
resource.TestCheckResourceAttr("megaport_vxc.vxc", "cost_centre", costCentreName),
resource.TestCheckResourceAttr("megaport_vxc.vxc", "a_end.vlan", "100"),
resource.TestCheckResourceAttr("megaport_vxc.vxc", "b_end.vlan", "101"),
resource.TestCheckResourceAttrSet("megaport_vxc.vxc", "product_uid"),
),
},
// Update Test - Change VXC Name, Untag A-End and B-End VLAN
{
Config: providerConfig + fmt.Sprintf(`
Expand Down

0 comments on commit 350830d

Please # to comment.