Skip to content

Commit 0cfa26d

Browse files
modular-magicianLuca Prete
and
Luca Prete
authored
[#11206] Add redundant_interface argument to cloud router interface (#6740) (#13032)
Co-authored-by: Luca Prete <[email protected]> Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Luca Prete <[email protected]>
1 parent 39adb0a commit 0cfa26d

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

.changelog/6740.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: Added optional `redundant_interface` argument to `google_compute_router_interface` resource
3+
```

google/resource_compute_router_interface.go

+15
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ func resourceComputeRouterInterface() *schema.Resource {
8080
ForceNew: true,
8181
Description: `The region this interface's router sits in. If not specified, the project region will be used. Changing this forces a new interface to be created.`,
8282
},
83+
84+
"redundant_interface": {
85+
Type: schema.TypeString,
86+
Optional: true,
87+
ForceNew: true,
88+
Description: `The name of the interface that is redundant to this interface.`,
89+
},
8390
},
8491
UseJSONNumber: true,
8592
}
@@ -123,6 +130,7 @@ func resourceComputeRouterInterfaceCreate(d *schema.ResourceData, meta interface
123130
}
124131

125132
ifaces := router.Interfaces
133+
126134
for _, iface := range ifaces {
127135
if iface.Name == ifaceName {
128136
d.SetId("")
@@ -132,6 +140,10 @@ func resourceComputeRouterInterfaceCreate(d *schema.ResourceData, meta interface
132140

133141
iface := &compute.RouterInterface{Name: ifaceName}
134142

143+
if riVal, ok := d.GetOk("redundant_interface"); ok {
144+
iface.RedundantInterface = riVal.(string)
145+
}
146+
135147
if ipVal, ok := d.GetOk("ip_range"); ok {
136148
iface.IpRange = ipVal.(string)
137149
}
@@ -225,6 +237,9 @@ func resourceComputeRouterInterfaceRead(d *schema.ResourceData, meta interface{}
225237
if err := d.Set("project", project); err != nil {
226238
return fmt.Errorf("Error setting project: %s", err)
227239
}
240+
if err := d.Set("redundant_interface", iface.RedundantInterface); err != nil {
241+
return fmt.Errorf("Error setting redundant interface: %s", err)
242+
}
228243
return nil
229244
}
230245
}

google/resource_compute_router_interface_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ func TestAccComputeRouterInterface_basic(t *testing.T) {
3636
})
3737
}
3838

39+
func TestAccComputeRouterInterface_redundant(t *testing.T) {
40+
t.Parallel()
41+
42+
routerName := fmt.Sprintf("tf-test-router-%s", randString(t, 10))
43+
vcrTest(t, resource.TestCase{
44+
PreCheck: func() { testAccPreCheck(t) },
45+
Providers: testAccProviders,
46+
CheckDestroy: testAccCheckComputeRouterInterfaceDestroyProducer(t),
47+
Steps: []resource.TestStep{
48+
{
49+
Config: testAccComputeRouterInterfaceRedundant(routerName),
50+
Check: testAccCheckComputeRouterInterfaceExists(
51+
t, "google_compute_router_interface.foobar_int2"),
52+
},
53+
{
54+
ResourceName: "google_compute_router_interface.foobar_int2",
55+
ImportState: true,
56+
ImportStateVerify: true,
57+
},
58+
},
59+
})
60+
}
61+
3962
func TestAccComputeRouterInterface_withTunnel(t *testing.T) {
4063
t.Parallel()
4164

@@ -249,6 +272,45 @@ resource "google_compute_router_interface" "foobar" {
249272
`, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName)
250273
}
251274

275+
func testAccComputeRouterInterfaceRedundant(routerName string) string {
276+
return fmt.Sprintf(`
277+
resource "google_compute_network" "foobar" {
278+
name = "%s-net"
279+
}
280+
281+
resource "google_compute_subnetwork" "foobar" {
282+
name = "%s-subnet"
283+
network = google_compute_network.foobar.self_link
284+
ip_cidr_range = "10.0.0.0/16"
285+
region = "us-central1"
286+
}
287+
288+
resource "google_compute_router" "foobar" {
289+
name = "%s"
290+
region = google_compute_subnetwork.foobar.region
291+
network = google_compute_network.foobar.self_link
292+
bgp {
293+
asn = 64514
294+
}
295+
}
296+
297+
resource "google_compute_router_interface" "foobar_int1" {
298+
name = "%s-int1"
299+
router = google_compute_router.foobar.name
300+
region = google_compute_router.foobar.region
301+
ip_range = "169.254.3.1/30"
302+
}
303+
304+
resource "google_compute_router_interface" "foobar_int2" {
305+
name = "%s-int2"
306+
router = google_compute_router.foobar.name
307+
region = google_compute_router.foobar.region
308+
ip_range = "169.254.4.1/30"
309+
redundant_interface = google_compute_router_interface.foobar_int1.name
310+
}
311+
`, routerName, routerName, routerName, routerName, routerName)
312+
}
313+
252314
func testAccComputeRouterInterfaceKeepRouter(routerName string) string {
253315
return fmt.Sprintf(`
254316
resource "google_compute_network" "foobar" {

website/docs/r/compute_router_interface.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ or both.
5252
be created. Only one of `vpn_tunnel` and `interconnect_attachment` can be
5353
specified.
5454

55+
* `redundant_interface` - (Optional) The name of the interface that is redundant to
56+
this interface. Changing this forces a new interface to
57+
be created.
58+
5559
* `project` - (Optional) The ID of the project in which this interface's router belongs. If it
5660
is not provided, the provider project is used. Changing this forces a new interface to be created.
5761

0 commit comments

Comments
 (0)