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

allow multiple fields in bgp_peer to be updatable #3134

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
3 changes: 3 additions & 0 deletions .changelog/4670.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: enabled fields `advertiseMode`, `advertisedGroups`, `peerAsn`, and `peerIpAddress` to be updatable on resource `google_compute_router_peer`
```
28 changes: 24 additions & 4 deletions google-beta/resource_compute_router_bgp_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ except the last character, which cannot be a dash.`,
"peer_asn": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `Peer BGP Autonomous System Number (ASN).
Each BGP interface may use a different value.`,
},
"peer_ip_address": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `IP address of the BGP interface outside Google Cloud Platform.
Only IPv4 is supported.`,
},
Expand All @@ -86,7 +84,6 @@ Only IPv4 is supported.`,
"advertise_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"DEFAULT", "CUSTOM", ""}, false),
Description: `User-specified flag to indicate which mode to use for advertisement.
Valid values of this enum field are: 'DEFAULT', 'CUSTOM' Default value: "DEFAULT" Possible values: ["DEFAULT", "CUSTOM"]`,
Expand All @@ -95,7 +92,6 @@ Valid values of this enum field are: 'DEFAULT', 'CUSTOM' Default value: "DEFAULT
"advertised_groups": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `User-specified list of prefix groups to advertise in custom
mode, which can take one of the following options:

Expand Down Expand Up @@ -394,12 +390,36 @@ func resourceComputeRouterBgpPeerUpdate(d *schema.ResourceData, meta interface{}
billingProject = project

obj := make(map[string]interface{})
peerIpAddressProp, err := expandNestedComputeRouterBgpPeerPeerIpAddress(d.Get("peer_ip_address"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("peer_ip_address"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, peerIpAddressProp)) {
obj["peerIpAddress"] = peerIpAddressProp
}
peerAsnProp, err := expandNestedComputeRouterBgpPeerPeerAsn(d.Get("peer_asn"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("peer_asn"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, peerAsnProp)) {
obj["peerAsn"] = peerAsnProp
}
advertisedRoutePriorityProp, err := expandNestedComputeRouterBgpPeerAdvertisedRoutePriority(d.Get("advertised_route_priority"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("advertised_route_priority"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, advertisedRoutePriorityProp)) {
obj["advertisedRoutePriority"] = advertisedRoutePriorityProp
}
advertiseModeProp, err := expandNestedComputeRouterBgpPeerAdvertiseMode(d.Get("advertise_mode"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("advertise_mode"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, advertiseModeProp)) {
obj["advertiseMode"] = advertiseModeProp
}
advertisedGroupsProp, err := expandNestedComputeRouterBgpPeerAdvertisedGroups(d.Get("advertised_groups"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("advertised_groups"); ok || !reflect.DeepEqual(v, advertisedGroupsProp) {
obj["advertisedGroups"] = advertisedGroupsProp
}
advertisedIpRangesProp, err := expandNestedComputeRouterBgpPeerAdvertisedIpRanges(d.Get("advertised_ip_ranges"), d, config)
if err != nil {
return err
Expand Down
98 changes: 98 additions & 0 deletions google-beta/resource_compute_router_bgp_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ func TestAccComputeRouterPeer_advertiseMode(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRouterPeerAdvertiseModeUpdate(routerName),
Check: testAccCheckComputeRouterPeerExists(
t, "google_compute_router_peer.foobar"),
},
{
ResourceName: "google_compute_router_peer.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -429,6 +439,94 @@ resource "google_compute_router_peer" "foobar" {
region = google_compute_router.foobar.region
peer_ip_address = "169.254.3.2"
peer_asn = 65515
advertise_mode = "DEFAULT"
interface = google_compute_router_interface.foobar.name
}
`, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName)
}

func testAccComputeRouterPeerAdvertiseModeUpdate(routerName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "foobar" {
name = "%s-net"
}

resource "google_compute_subnetwork" "foobar" {
name = "%s-subnet"
network = google_compute_network.foobar.self_link
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
}

resource "google_compute_address" "foobar" {
name = "%s-addr"
region = google_compute_subnetwork.foobar.region
}

resource "google_compute_vpn_gateway" "foobar" {
name = "%s-gateway"
network = google_compute_network.foobar.self_link
region = google_compute_subnetwork.foobar.region
}

resource "google_compute_forwarding_rule" "foobar_esp" {
name = "%s-fr1"
region = google_compute_vpn_gateway.foobar.region
ip_protocol = "ESP"
ip_address = google_compute_address.foobar.address
target = google_compute_vpn_gateway.foobar.self_link
}

resource "google_compute_forwarding_rule" "foobar_udp500" {
name = "%s-fr2"
region = google_compute_forwarding_rule.foobar_esp.region
ip_protocol = "UDP"
port_range = "500-500"
ip_address = google_compute_address.foobar.address
target = google_compute_vpn_gateway.foobar.self_link
}

resource "google_compute_forwarding_rule" "foobar_udp4500" {
name = "%s-fr3"
region = google_compute_forwarding_rule.foobar_udp500.region
ip_protocol = "UDP"
port_range = "4500-4500"
ip_address = google_compute_address.foobar.address
target = google_compute_vpn_gateway.foobar.self_link
}

resource "google_compute_router" "foobar" {
name = "%s"
region = google_compute_forwarding_rule.foobar_udp500.region
network = google_compute_network.foobar.self_link
bgp {
asn = 64514
}
}

resource "google_compute_vpn_tunnel" "foobar" {
name = "%s"
region = google_compute_forwarding_rule.foobar_udp4500.region
target_vpn_gateway = google_compute_vpn_gateway.foobar.self_link
shared_secret = "unguessable"
peer_ip = "8.8.8.8"
router = google_compute_router.foobar.name
}

resource "google_compute_router_interface" "foobar" {
name = "%s"
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
ip_range = "169.254.3.1/30"
vpn_tunnel = google_compute_vpn_tunnel.foobar.name
}

resource "google_compute_router_peer" "foobar" {
name = "%s"
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
peer_ip_address = "169.254.3.3"
peer_asn = 65516
advertised_route_priority = 100
advertise_mode = "CUSTOM"
advertised_groups = ["ALL_SUBNETS"]
Expand Down