terraform-provider-google/google/resource_redis_instance_generated_test.go
The Magician 2ab6d1995f Add = to map declarations in examples/tests (#2755)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2018-12-27 07:51:23 -08:00

128 lines
3.3 KiB
Go

// ----------------------------------------------------------------------------
//
// *** 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"
)
func TestAccRedisInstance_redisInstanceBasicExample(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedisInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccRedisInstance_redisInstanceBasicExample(acctest.RandString(10)),
},
{
ResourceName: "google_redis_instance.cache",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}
func testAccRedisInstance_redisInstanceBasicExample(val string) string {
return fmt.Sprintf(`
resource "google_redis_instance" "cache" {
name = "memory-cache-%s"
memory_size_gb = 1
}
`, val,
)
}
func TestAccRedisInstance_redisInstanceFullExample(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedisInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccRedisInstance_redisInstanceFullExample(acctest.RandString(10)),
},
{
ResourceName: "google_redis_instance.cache",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}
func testAccRedisInstance_redisInstanceFullExample(val string) string {
return fmt.Sprintf(`
resource "google_redis_instance" "cache" {
name = "ha-memory-cache-%s"
tier = "STANDARD_HA"
memory_size_gb = 1
location_id = "us-central1-a"
alternative_location_id = "us-central1-f"
authorized_network = "${google_compute_network.auto-network.self_link}"
redis_version = "REDIS_3_2"
display_name = "Terraform Test Instance"
reserved_ip_range = "192.168.0.0/29"
labels = {
my_key = "my_val"
other_key = "other_val"
}
}
resource "google_compute_network" "auto-network" {
name = "authorized-network-%s"
}
`, val, val,
)
}
func testAccCheckRedisInstanceDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_redis_instance" {
continue
}
config := testAccProvider.Meta().(*Config)
url, err := replaceVarsForTest(rs, "https://redis.googleapis.com/v1/projects/{{project}}/locations/{{region}}/instances/{{name}}")
if err != nil {
return err
}
_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("RedisInstance still exists at %s", url)
}
}
return nil
}