From 4692b94bf1d6508241e48a9b130baa2bf7201a16 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 25 Aug 2021 14:18:18 -0500 Subject: [PATCH] Allow setting ip_address of bgp router peer (#5098) (#9913) * Allow setting ip_address of bgp router peer * Mark O+C Signed-off-by: Modular Magician --- .changelog/5098.txt | 3 ++ .../resource_compute_router_bgp_peer_test.go | 1 + google/resource_compute_router_peer.go | 29 +++++++++++++++---- .../docs/r/compute_router_peer.html.markdown | 9 +++--- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 .changelog/5098.txt diff --git a/.changelog/5098.txt b/.changelog/5098.txt new file mode 100644 index 00000000000..453c040dcf2 --- /dev/null +++ b/.changelog/5098.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: allowed setting `ip_address` field of `google_compute_router_peer` +``` diff --git a/google/resource_compute_router_bgp_peer_test.go b/google/resource_compute_router_bgp_peer_test.go index 3a7d76751ae..e08bcb3f78d 100644 --- a/google/resource_compute_router_bgp_peer_test.go +++ b/google/resource_compute_router_bgp_peer_test.go @@ -315,6 +315,7 @@ resource "google_compute_router_peer" "foobar" { name = "%s" router = google_compute_router.foobar.name region = google_compute_router.foobar.region + ip_address = "169.254.3.1" peer_ip_address = "169.254.3.2" peer_asn = 65515 advertised_route_priority = 100 diff --git a/google/resource_compute_router_peer.go b/google/resource_compute_router_peer.go index 0cfb8d2ffd3..669562ae15b 100644 --- a/google/resource_compute_router_peer.go +++ b/google/resource_compute_router_peer.go @@ -149,6 +149,13 @@ If set to true, the peer connection can be established with routing information. The default is true.`, Default: true, }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: `IP address of the interface inside Google Cloud Platform. +Only IPv4 is supported.`, + }, "region": { Type: schema.TypeString, Computed: true, @@ -157,12 +164,6 @@ The default is true.`, DiffSuppressFunc: compareSelfLinkOrResourceName, Description: `Region where the router and BgpPeer reside. If it is not provided, the provider region is used.`, - }, - "ip_address": { - Type: schema.TypeString, - Computed: true, - Description: `IP address of the interface inside Google Cloud Platform. -Only IPv4 is supported.`, }, "management_type": { Type: schema.TypeString, @@ -209,6 +210,12 @@ func resourceComputeRouterBgpPeerCreate(d *schema.ResourceData, meta interface{} } else if v, ok := d.GetOkExists("interface"); !isEmptyValue(reflect.ValueOf(interfaceNameProp)) && (ok || !reflect.DeepEqual(v, interfaceNameProp)) { obj["interfaceName"] = interfaceNameProp } + ipAddressProp, err := expandNestedComputeRouterBgpPeerIpAddress(d.Get("ip_address"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_address"); !isEmptyValue(reflect.ValueOf(ipAddressProp)) && (ok || !reflect.DeepEqual(v, ipAddressProp)) { + obj["ipAddress"] = ipAddressProp + } peerIpAddressProp, err := expandNestedComputeRouterBgpPeerPeerIpAddress(d.Get("peer_ip_address"), d, config) if err != nil { return err @@ -409,6 +416,12 @@ func resourceComputeRouterBgpPeerUpdate(d *schema.ResourceData, meta interface{} billingProject = project obj := make(map[string]interface{}) + ipAddressProp, err := expandNestedComputeRouterBgpPeerIpAddress(d.Get("ip_address"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_address"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipAddressProp)) { + obj["ipAddress"] = ipAddressProp + } peerIpAddressProp, err := expandNestedComputeRouterBgpPeerPeerIpAddress(d.Get("peer_ip_address"), d, config) if err != nil { return err @@ -683,6 +696,10 @@ func expandNestedComputeRouterBgpPeerInterface(v interface{}, d TerraformResourc return v, nil } +func expandNestedComputeRouterBgpPeerIpAddress(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandNestedComputeRouterBgpPeerPeerIpAddress(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/website/docs/r/compute_router_peer.html.markdown b/website/docs/r/compute_router_peer.html.markdown index 84ffa1101ca..f9ae50c2093 100644 --- a/website/docs/r/compute_router_peer.html.markdown +++ b/website/docs/r/compute_router_peer.html.markdown @@ -101,6 +101,11 @@ The following arguments are supported: - - - +* `ip_address` - + (Optional) + IP address of the interface inside Google Cloud Platform. + Only IPv4 is supported. + * `advertised_route_priority` - (Optional) The priority of routes advertised to this BGP peer. @@ -169,10 +174,6 @@ In addition to the arguments listed above, the following computed attributes are * `id` - an identifier for the resource with format `projects/{{project}}/regions/{{region}}/routers/{{router}}/{{name}}` -* `ip_address` - - IP address of the interface inside Google Cloud Platform. - Only IPv4 is supported. - * `management_type` - The resource that configures and manages this BGP peer. * `MANAGED_BY_USER` is the default value and can be managed by