diff --git a/.changelog/6740.txt b/.changelog/6740.txt new file mode 100644 index 00000000000..031673d0988 --- /dev/null +++ b/.changelog/6740.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: Added optional `redundant_interface` argument to `google_compute_router_interface` resource +``` diff --git a/google/resource_compute_router_interface.go b/google/resource_compute_router_interface.go index 98eca2ec7a7..4c4615cf303 100644 --- a/google/resource_compute_router_interface.go +++ b/google/resource_compute_router_interface.go @@ -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, } @@ -123,6 +130,7 @@ func resourceComputeRouterInterfaceCreate(d *schema.ResourceData, meta interface } ifaces := router.Interfaces + for _, iface := range ifaces { if iface.Name == ifaceName { d.SetId("") @@ -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) } @@ -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 } } diff --git a/google/resource_compute_router_interface_test.go b/google/resource_compute_router_interface_test.go index b6fb1e87f9c..fc53cccde8a 100644 --- a/google/resource_compute_router_interface_test.go +++ b/google/resource_compute_router_interface_test.go @@ -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() @@ -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" { diff --git a/website/docs/r/compute_router_interface.html.markdown b/website/docs/r/compute_router_interface.html.markdown index f7a1fd0f560..921cc31636b 100644 --- a/website/docs/r/compute_router_interface.html.markdown +++ b/website/docs/r/compute_router_interface.html.markdown @@ -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.