@@ -2,10 +2,12 @@ package google
2
2
3
3
import (
4
4
"fmt"
5
+ "strings"
5
6
"testing"
6
7
7
8
"github.com/hashicorp/terraform/helper/acctest"
8
9
"github.com/hashicorp/terraform/helper/resource"
10
+ "github.com/hashicorp/terraform/terraform"
9
11
)
10
12
11
13
func TestAccRedisInstance_basic (t * testing.T ) {
@@ -16,7 +18,7 @@ func TestAccRedisInstance_basic(t *testing.T) {
16
18
resource .Test (t , resource.TestCase {
17
19
PreCheck : func () { testAccPreCheck (t ) },
18
20
Providers : testAccProviders ,
19
- CheckDestroy : testAccCheckComputeAddressDestroy ,
21
+ CheckDestroy : testAccCheckRedisInstanceDestroy ,
20
22
Steps : []resource.TestStep {
21
23
resource.TestStep {
22
24
Config : testAccRedisInstance_basic (name ),
@@ -38,7 +40,7 @@ func TestAccRedisInstance_update(t *testing.T) {
38
40
resource .Test (t , resource.TestCase {
39
41
PreCheck : func () { testAccPreCheck (t ) },
40
42
Providers : testAccProviders ,
41
- CheckDestroy : testAccCheckComputeAddressDestroy ,
43
+ CheckDestroy : testAccCheckRedisInstanceDestroy ,
42
44
Steps : []resource.TestStep {
43
45
resource.TestStep {
44
46
Config : testAccRedisInstance_update (name ),
@@ -69,7 +71,7 @@ func TestAccRedisInstance_full(t *testing.T) {
69
71
resource .Test (t , resource.TestCase {
70
72
PreCheck : func () { testAccPreCheck (t ) },
71
73
Providers : testAccProviders ,
72
- CheckDestroy : testAccCheckComputeAddressDestroy ,
74
+ CheckDestroy : testAccCheckRedisInstanceDestroy ,
73
75
Steps : []resource.TestStep {
74
76
resource.TestStep {
75
77
Config : testAccRedisInstance_full (name , network ),
@@ -83,6 +85,31 @@ func TestAccRedisInstance_full(t *testing.T) {
83
85
})
84
86
}
85
87
88
+ func testAccCheckRedisInstanceDestroy (s * terraform.State ) error {
89
+ config := testAccProvider .Meta ().(* Config )
90
+
91
+ for _ , rs := range s .RootModule ().Resources {
92
+ if rs .Type != "google_redis_instance" {
93
+ continue
94
+ }
95
+
96
+ redisIdParts := strings .Split (rs .Primary .ID , "/" )
97
+ if len (redisIdParts ) != 3 {
98
+ return fmt .Errorf ("Unexpected resource ID %s, expected {project}/{region}/{name}" , rs .Primary .ID )
99
+ }
100
+
101
+ project , region , inst := redisIdParts [0 ], redisIdParts [1 ], redisIdParts [2 ]
102
+
103
+ name := fmt .Sprintf ("projects/%s/locations/%s/instances/%s" , project , region , inst )
104
+ _ , err := config .clientRedis .Projects .Locations .Get (name ).Do ()
105
+ if err == nil {
106
+ return fmt .Errorf ("Redis instance still exists" )
107
+ }
108
+ }
109
+
110
+ return nil
111
+ }
112
+
86
113
func testAccRedisInstance_basic (name string ) string {
87
114
return fmt .Sprintf (`
88
115
resource "google_redis_instance" "test" {
@@ -130,6 +157,8 @@ resource "google_redis_instance" "test" {
130
157
tier = "STANDARD_HA"
131
158
memory_size_gb = 1
132
159
160
+ authorized_network = "${google_compute_network.test.self_link}"
161
+
133
162
region = "us-central1"
134
163
location_id = "us-central1-a"
135
164
alternative_location_id = "us-central1-f"
@@ -142,5 +171,5 @@ resource "google_redis_instance" "test" {
142
171
my_key = "my_val"
143
172
other_key = "other_val"
144
173
}
145
- }` , name , network )
174
+ }` , network , name )
146
175
}
0 commit comments