blob: 83588d78ad2664566853e6bd6d4508f75d16d7c4 [file] [log] [blame]
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// 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 redis_test
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)
func TestAccRedisCluster_redisClusterHaExample(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"prevent_destroy": false,
"random_suffix": acctest.RandString(t, 10),
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckRedisClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccRedisCluster_redisClusterHaExample(context),
},
{
ResourceName: "google_redis_cluster.cluster-ha",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"psc_configs", "name", "region"},
},
},
})
}
func testAccRedisCluster_redisClusterHaExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_redis_cluster" "cluster-ha" {
name = "tf-test-ha-cluster%{random_suffix}"
shard_count = 3
psc_configs {
network = google_compute_network.producer_net.id
}
region = "us-central1"
replica_count = 1
transit_encryption_mode = "TRANSIT_ENCRYPTION_MODE_DISABLED"
authorization_mode = "AUTH_MODE_DISABLED"
depends_on = [
google_network_connectivity_service_connection_policy.default
]
lifecycle {
prevent_destroy = %{prevent_destroy}
}
}
resource "google_network_connectivity_service_connection_policy" "default" {
name = "mypolicy%{random_suffix}"
location = "us-central1"
service_class = "gcp-memorystore-redis"
description = "my basic service connection policy"
network = google_compute_network.producer_net.id
psc_config {
subnetworks = [google_compute_subnetwork.producer_subnet.id]
}
}
resource "google_compute_subnetwork" "producer_subnet" {
name = "mysubnet%{random_suffix}"
ip_cidr_range = "10.0.0.248/29"
region = "us-central1"
network = google_compute_network.producer_net.id
}
resource "google_compute_network" "producer_net" {
name = "mynetwork%{random_suffix}"
auto_create_subnetworks = false
}
`, context)
}
func testAccCheckRedisClusterDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_redis_cluster" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := acctest.GoogleProviderConfig(t)
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{RedisBasePath}}projects/{{project}}/locations/{{region}}/clusters/{{name}}")
if err != nil {
return err
}
billingProject := ""
if config.BillingProject != "" {
billingProject = config.BillingProject
}
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("RedisCluster still exists at %s", url)
}
}
return nil
}
}