Skip to content

Commit

Permalink
[#11206] Add redundant_interface argument to cloud router interface (#…
Browse files Browse the repository at this point in the history
…6740) (#13032)

Co-authored-by: Luca Prete <lucaprete@google.com>
Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Luca Prete <lucaprete@google.com>
  • Loading branch information
modular-magician and Luca Prete committed Nov 14, 2022
1 parent 39adb0a commit 0cfa26d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
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

0 comments on commit 0cfa26d

Please sign in to comment.