2018-09-24 22:35:43 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2018-10-26 18:03:43 +00:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2018-09-24 22:35:43 +00:00
|
|
|
)
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func TestAccComputeRouter_routerBasicExample(t *testing.T) {
|
2018-09-24 22:35:43 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeRouterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2018-11-09 21:02:03 +00:00
|
|
|
Config: testAccComputeRouter_routerBasicExample(acctest.RandString(10)),
|
2018-09-24 22:35:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_compute_router.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-09 21:02:03 +00:00
|
|
|
func testAccComputeRouter_routerBasicExample(val string) string {
|
2018-09-24 22:35:43 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_router" "foobar" {
|
|
|
|
name = "my-router-%s"
|
|
|
|
network = "${google_compute_network.foobar.name}"
|
|
|
|
bgp {
|
|
|
|
asn = 64514
|
|
|
|
advertise_mode = "CUSTOM"
|
|
|
|
advertised_groups = ["ALL_SUBNETS"]
|
|
|
|
advertised_ip_ranges {
|
|
|
|
range = "1.2.3.4"
|
|
|
|
}
|
|
|
|
advertised_ip_ranges {
|
|
|
|
range = "6.7.0.0/16"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_network" "foobar" {
|
|
|
|
name = "my-network-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
`, val, val,
|
|
|
|
)
|
|
|
|
}
|
2018-10-26 18:03:43 +00:00
|
|
|
|
|
|
|
func testAccCheckComputeRouterDestroy(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_compute_router" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/routers/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sendRequest(config, "GET", url, nil)
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("ComputeRouter still exists at %s", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|