Skip to content

Commit 7fbfadb

Browse files
Fix for unable to set bgp_always_compare_med in google_compute_network from true to false (#14424) (#23477)
[upstream:14bb73bd4034b5015206b319f46c3f39619c509e] Signed-off-by: Modular Magician <[email protected]>
1 parent a69ffdf commit 7fbfadb

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.changelog/14424.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed an issue with `bgp_always_compare_med` in `google_compute_network` where it was unable to be set from `true` to `false`
3+
```

google/services/compute/resource_compute_network.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,16 @@ func resourceComputeNetworkEncoder(d *schema.ResourceData, meta interface{}, obj
947947
}
948948

949949
func resourceComputeNetworkUpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
950-
delete(obj, "numeric_id") // Field doesn't exist in the API
950+
// BGP always-compare-med
951+
if d.HasChange("bgp_always_compare_med") {
952+
if _, ok := obj["routingConfig"]; !ok {
953+
obj["routingConfig"] = make(map[string]interface{})
954+
}
955+
obj["routingConfig"].(map[string]interface{})["bgpAlwaysCompareMed"] = d.Get("bgp_always_compare_med").(bool)
956+
}
957+
958+
// now clean up the rest
959+
delete(obj, "numeric_id")
951960
return obj, nil
952961
}
953962

google/services/compute/resource_compute_network_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ func TestAccComputeNetwork_bgpAlwaysCompareMedAndUpdate(t *testing.T) {
223223
resource.TestCheckResourceAttr("google_compute_network.acc_network_bgp_always_compare_med", "bgp_always_compare_med", "true"),
224224
),
225225
},
226+
{
227+
Config: testAccComputeNetwork_bgp_always_compare_med(networkName, false),
228+
Check: resource.ComposeTestCheckFunc(
229+
testAccCheckComputeNetworkExists(
230+
t, "google_compute_network.acc_network_bgp_always_compare_med", &network),
231+
resource.TestCheckResourceAttr("google_compute_network.acc_network_bgp_always_compare_med", "bgp_always_compare_med", "false"),
232+
),
233+
},
226234
},
227235
})
228236
}

0 commit comments

Comments
 (0)