Skip to content

Commit be6413f

Browse files
Add keepalive to compute router (#5760) (#4089)
Signed-off-by: Modular Magician <[email protected]>
1 parent 9cc54cb commit be6413f

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

.changelog/5760.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added support for `keepalive_interval` to `google_compute_router.bgp`
3+
```

google-beta/resource_compute_router.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ CIDR-formatted string.`,
142142
},
143143
},
144144
},
145+
"keepalive_interval": {
146+
Type: schema.TypeInt,
147+
Optional: true,
148+
Description: `The interval in seconds between BGP keepalive messages that are sent to the peer.
149+
Hold time is three times the interval at which keepalive messages are sent, and the hold time is the
150+
maximum number of seconds allowed to elapse between successive keepalive messages that BGP receives from a peer.
151+
BGP will use the smaller of either the local hold time value or the peer's hold time value as the hold time for
152+
the BGP connection between the two peers. If set, this value must be between 20 and 60. The default is 20.`,
153+
Default: 20,
154+
},
145155
},
146156
},
147157
},
@@ -523,6 +533,8 @@ func flattenComputeRouterBgp(v interface{}, d *schema.ResourceData, config *Conf
523533
flattenComputeRouterBgpAdvertisedGroups(original["advertisedGroups"], d, config)
524534
transformed["advertised_ip_ranges"] =
525535
flattenComputeRouterBgpAdvertisedIpRanges(original["advertisedIpRanges"], d, config)
536+
transformed["keepalive_interval"] =
537+
flattenComputeRouterBgpKeepaliveInterval(original["keepaliveInterval"], d, config)
526538
return []interface{}{transformed}
527539
}
528540
func flattenComputeRouterBgpAsn(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -577,6 +589,23 @@ func flattenComputeRouterBgpAdvertisedIpRangesDescription(v interface{}, d *sche
577589
return v
578590
}
579591

592+
func flattenComputeRouterBgpKeepaliveInterval(v interface{}, d *schema.ResourceData, config *Config) interface{} {
593+
// Handles the string fixed64 format
594+
if strVal, ok := v.(string); ok {
595+
if intVal, err := stringToFixed64(strVal); err == nil {
596+
return intVal
597+
}
598+
}
599+
600+
// number values are represented as float64
601+
if floatVal, ok := v.(float64); ok {
602+
intVal := int(floatVal)
603+
return intVal
604+
}
605+
606+
return v // let terraform core handle it otherwise
607+
}
608+
580609
func flattenComputeRouterEncryptedInterconnectRouter(v interface{}, d *schema.ResourceData, config *Config) interface{} {
581610
return v
582611
}
@@ -641,6 +670,13 @@ func expandComputeRouterBgp(v interface{}, d TerraformResourceData, config *Conf
641670
transformed["advertisedIpRanges"] = transformedAdvertisedIpRanges
642671
}
643672

673+
transformedKeepaliveInterval, err := expandComputeRouterBgpKeepaliveInterval(original["keepalive_interval"], d, config)
674+
if err != nil {
675+
return nil, err
676+
} else if val := reflect.ValueOf(transformedKeepaliveInterval); val.IsValid() && !isEmptyValue(val) {
677+
transformed["keepaliveInterval"] = transformedKeepaliveInterval
678+
}
679+
644680
return transformed, nil
645681
}
646682

@@ -693,6 +729,10 @@ func expandComputeRouterBgpAdvertisedIpRangesDescription(v interface{}, d Terraf
693729
return v, nil
694730
}
695731

732+
func expandComputeRouterBgpKeepaliveInterval(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
733+
return v, nil
734+
}
735+
696736
func expandComputeRouterEncryptedInterconnectRouter(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
697737
return v, nil
698738
}

google-beta/resource_compute_router_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ resource "google_compute_router" "foobar" {
222222
advertised_ip_ranges {
223223
range = "6.7.0.0/16"
224224
}
225+
keepalive_interval = 25
225226
}
226227
}
227228
`, routerName, routerName)

website/docs/r/compute_router.html.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ The following arguments are supported:
163163
Leave this field blank to advertise no custom IP ranges.
164164
Structure is [documented below](#nested_advertised_ip_ranges).
165165

166+
* `keepalive_interval` -
167+
(Optional)
168+
The interval in seconds between BGP keepalive messages that are sent to the peer.
169+
Hold time is three times the interval at which keepalive messages are sent, and the hold time is the
170+
maximum number of seconds allowed to elapse between successive keepalive messages that BGP receives from a peer.
171+
BGP will use the smaller of either the local hold time value or the peer's hold time value as the hold time for
172+
the BGP connection between the two peers. If set, this value must be between 20 and 60. The default is 20.
173+
166174

167175
<a name="nested_advertised_ip_ranges"></a>The `advertised_ip_ranges` block supports:
168176

0 commit comments

Comments
 (0)