terraform-provider-google/google/resource_compute_subnetwork_generated_test.go

88 lines
2.4 KiB
Go
Raw Normal View History

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"
"github.com/hashicorp/terraform/terraform"
2018-09-24 22:35:43 +00:00
)
2018-10-24 19:06:09 +00:00
func TestAccComputeSubnetwork_SubnetworkBasicExample(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: testAccCheckComputeSubnetworkDestroy,
Steps: []resource.TestStep{
{
2018-10-24 19:06:09 +00:00
Config: testAccComputeSubnetwork_SubnetworkBasicExample(acctest.RandString(10)),
2018-09-24 22:35:43 +00:00
},
{
ResourceName: "google_compute_subnetwork.network-with-private-secondary-ip-ranges",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
2018-10-24 19:06:09 +00:00
func testAccComputeSubnetwork_SubnetworkBasicExample(val string) string {
2018-09-24 22:35:43 +00:00
return fmt.Sprintf(`
resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
name = "test-subnetwork-%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"
secondary_ip_range {
range_name = "tf-test-secondary-range-update1"
ip_cidr_range = "192.168.10.0/24"
}
}
resource "google_compute_network" "custom-test" {
name = "test-network-%s"
auto_create_subnetworks = false
}
`, val, val,
)
}
func testAccCheckComputeSubnetworkDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_subnetwork" {
continue
}
config := testAccProvider.Meta().(*Config)
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
if err != nil {
return err
}
_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeSubnetwork still exists at %s", url)
}
}
return nil
}