mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-04 17:51:11 +00:00
132 lines
3.3 KiB
Go
132 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"
|
|
"strings"
|
|
"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 name, rs := range s.RootModule().Resources {
|
|
if rs.Type != "google_redis_instance" {
|
|
continue
|
|
}
|
|
if strings.HasPrefix(name, "data.") {
|
|
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
|
|
}
|