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

[#11206] Add redundant_interface argument to cloud router interface #13032

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6740.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: Added optional `redundant_interface` argument to `google_compute_router_interface` resource
```
15 changes: 15 additions & 0 deletions google/resource_compute_router_interface.go
Expand Up @@ -80,6 +80,13 @@ func resourceComputeRouterInterface() *schema.Resource {
ForceNew: true,
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.`,
},

"redundant_interface": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The name of the interface that is redundant to this interface.`,
},
},
UseJSONNumber: true,
}
Expand Down Expand Up @@ -123,6 +130,7 @@ func resourceComputeRouterInterfaceCreate(d *schema.ResourceData, meta interface
}

ifaces := router.Interfaces

for _, iface := range ifaces {
if iface.Name == ifaceName {
d.SetId("")
Expand All @@ -132,6 +140,10 @@ func resourceComputeRouterInterfaceCreate(d *schema.ResourceData, meta interface

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

if riVal, ok := d.GetOk("redundant_interface"); ok {
iface.RedundantInterface = riVal.(string)
}

if ipVal, ok := d.GetOk("ip_range"); ok {
iface.IpRange = ipVal.(string)
}
Expand Down Expand Up @@ -225,6 +237,9 @@ func resourceComputeRouterInterfaceRead(d *schema.ResourceData, meta interface{}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error setting project: %s", err)
}
if err := d.Set("redundant_interface", iface.RedundantInterface); err != nil {
return fmt.Errorf("Error setting redundant interface: %s", err)
}
return nil
}
}
Expand Down
62 changes: 62 additions & 0 deletions google/resource_compute_router_interface_test.go
Expand Up @@ -36,6 +36,29 @@ func TestAccComputeRouterInterface_basic(t *testing.T) {
})
}

func TestAccComputeRouterInterface_redundant(t *testing.T) {
t.Parallel()

routerName := fmt.Sprintf("tf-test-router-%s", randString(t, 10))
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeRouterInterfaceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRouterInterfaceRedundant(routerName),
Check: testAccCheckComputeRouterInterfaceExists(
t, "google_compute_router_interface.foobar_int2"),
},
{
ResourceName: "google_compute_router_interface.foobar_int2",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccComputeRouterInterface_withTunnel(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -249,6 +272,45 @@ resource "google_compute_router_interface" "foobar" {
`, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName, routerName)
}

func testAccComputeRouterInterfaceRedundant(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_router" "foobar" {
name = "%s"
region = google_compute_subnetwork.foobar.region
network = google_compute_network.foobar.self_link
bgp {
asn = 64514
}
}

resource "google_compute_router_interface" "foobar_int1" {
name = "%s-int1"
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
ip_range = "169.254.3.1/30"
}

resource "google_compute_router_interface" "foobar_int2" {
name = "%s-int2"
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
ip_range = "169.254.4.1/30"
redundant_interface = google_compute_router_interface.foobar_int1.name
}
`, routerName, routerName, routerName, routerName, routerName)
}

func testAccComputeRouterInterfaceKeepRouter(routerName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "foobar" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/compute_router_interface.html.markdown
Expand Up @@ -52,6 +52,10 @@ or both.
be created. Only one of `vpn_tunnel` and `interconnect_attachment` can be
specified.

* `redundant_interface` - (Optional) The name of the interface that is redundant to
this interface. Changing this forces a new interface to
be created.

* `project` - (Optional) The ID of the project in which this interface's router belongs. If it
is not provided, the provider project is used. Changing this forces a new interface to be created.

Expand Down