@@ -31,7 +31,7 @@ func TestAccBigtableInstance_basic(t *testing.T) {
3131 ResourceName : "google_bigtable_instance.instance" ,
3232 ImportState : true ,
3333 ImportStateVerify : true ,
34- ImportStateVerifyIgnore : []string {"instance_type" }, // we don't read instance type back
34+ ImportStateVerifyIgnore : []string {"deletion_protection" , " instance_type" }, // we don't read instance type back
3535 },
3636 {
3737 Config : testAccBigtableInstance (instanceName , 4 ),
@@ -40,7 +40,7 @@ func TestAccBigtableInstance_basic(t *testing.T) {
4040 ResourceName : "google_bigtable_instance.instance" ,
4141 ImportState : true ,
4242 ImportStateVerify : true ,
43- ImportStateVerifyIgnore : []string {"instance_type" }, // we don't read instance type back
43+ ImportStateVerifyIgnore : []string {"deletion_protection" , " instance_type" }, // we don't read instance type back
4444 },
4545 },
4646 })
@@ -67,7 +67,7 @@ func TestAccBigtableInstance_cluster(t *testing.T) {
6767 ResourceName : "google_bigtable_instance.instance" ,
6868 ImportState : true ,
6969 ImportStateVerify : true ,
70- ImportStateVerifyIgnore : []string {"instance_type" }, // we don't read instance type back
70+ ImportStateVerifyIgnore : []string {"deletion_protection" , " instance_type" }, // we don't read instance type back
7171 },
7272 {
7373 Config : testAccBigtableInstance_clusterReordered (instanceName , 5 ),
@@ -76,7 +76,7 @@ func TestAccBigtableInstance_cluster(t *testing.T) {
7676 ResourceName : "google_bigtable_instance.instance" ,
7777 ImportState : true ,
7878 ImportStateVerify : true ,
79- ImportStateVerifyIgnore : []string {"instance_type" }, // we don't read instance type back
79+ ImportStateVerifyIgnore : []string {"deletion_protection" , " instance_type" }, // we don't read instance type back
8080 },
8181 {
8282 Config : testAccBigtableInstance_clusterModified (instanceName , 5 ),
@@ -85,7 +85,7 @@ func TestAccBigtableInstance_cluster(t *testing.T) {
8585 ResourceName : "google_bigtable_instance.instance" ,
8686 ImportState : true ,
8787 ImportStateVerify : true ,
88- ImportStateVerifyIgnore : []string {"instance_type" }, // we don't read instance type back
88+ ImportStateVerifyIgnore : []string {"deletion_protection" , " instance_type" }, // we don't read instance type back
8989 },
9090 {
9191 Config : testAccBigtableInstance_clusterReordered (instanceName , 5 ),
@@ -94,7 +94,7 @@ func TestAccBigtableInstance_cluster(t *testing.T) {
9494 ResourceName : "google_bigtable_instance.instance" ,
9595 ImportState : true ,
9696 ImportStateVerify : true ,
97- ImportStateVerifyIgnore : []string {"instance_type" }, // we don't read instance type back
97+ ImportStateVerifyIgnore : []string {"deletion_protection" , " instance_type" }, // we don't read instance type back
9898 },
9999 },
100100 })
@@ -117,7 +117,38 @@ func TestAccBigtableInstance_development(t *testing.T) {
117117 ResourceName : "google_bigtable_instance.instance" ,
118118 ImportState : true ,
119119 ImportStateVerify : true ,
120- ImportStateVerifyIgnore : []string {"instance_type" }, // we don't read instance type back
120+ ImportStateVerifyIgnore : []string {"deletion_protection" , "instance_type" }, // we don't read instance type back
121+ },
122+ },
123+ })
124+ }
125+
126+ func TestAccBigtableInstance_allowDestroy (t * testing.T ) {
127+ t .Parallel ()
128+
129+ instanceName := fmt .Sprintf ("tf-test-%s" , randString (t , 10 ))
130+
131+ vcrTest (t , resource.TestCase {
132+ PreCheck : func () { testAccPreCheck (t ) },
133+ Providers : testAccProviders ,
134+ CheckDestroy : testAccCheckBigtableInstanceDestroyProducer (t ),
135+ Steps : []resource.TestStep {
136+ {
137+ Config : testAccBigtableInstance_noAllowDestroy (instanceName , 3 ),
138+ },
139+ {
140+ ResourceName : "google_bigtable_instance.instance" ,
141+ ImportState : true ,
142+ ImportStateVerify : true ,
143+ ImportStateVerifyIgnore : []string {"deletion_protection" , "instance_type" }, // we don't read instance type back
144+ },
145+ {
146+ Config : testAccBigtableInstance_noAllowDestroy (instanceName , 3 ),
147+ Destroy : true ,
148+ ExpectError : regexp .MustCompile ("deletion_protection" ),
149+ },
150+ {
151+ Config : testAccBigtableInstance (instanceName , 3 ),
121152 },
122153 },
123154 })
@@ -159,6 +190,8 @@ resource "google_bigtable_instance" "instance" {
159190 num_nodes = %d
160191 storage_type = "HDD"
161192 }
193+
194+ deletion_protection = false
162195}
163196` , instanceName , instanceName , numNodes )
164197}
@@ -199,6 +232,8 @@ resource "google_bigtable_instance" "instance" {
199232 num_nodes = %d
200233 storage_type = "HDD"
201234 }
235+
236+ deletion_protection = false
202237}
203238` , instanceName , instanceName , numNodes , instanceName , numNodes , instanceName , numNodes , instanceName , numNodes )
204239}
@@ -237,6 +272,8 @@ resource "google_bigtable_instance" "instance" {
237272 num_nodes = 3
238273 storage_type = "HDD"
239274 }
275+
276+ deletion_protection = false
240277}
241278` , instanceName , instanceName , instanceName , instanceName , instanceName , instanceName )
242279}
@@ -269,6 +306,8 @@ resource "google_bigtable_instance" "instance" {
269306 num_nodes = %d
270307 storage_type = "HDD"
271308 }
309+
310+ deletion_protection = false
272311}
273312` , instanceName , instanceName , numNodes , instanceName , numNodes , instanceName , numNodes , instanceName , numNodes )
274313}
@@ -295,6 +334,8 @@ resource "google_bigtable_instance" "instance" {
295334 num_nodes = %d
296335 storage_type = "HDD"
297336 }
337+
338+ deletion_protection = false
298339}
299340` , instanceName , instanceName , numNodes , instanceName , numNodes , instanceName , numNodes )
300341}
@@ -308,6 +349,22 @@ resource "google_bigtable_instance" "instance" {
308349 zone = "us-central1-b"
309350 }
310351 instance_type = "DEVELOPMENT"
352+
353+ deletion_protection = false
311354}
312355` , instanceName , instanceName )
313356}
357+
358+ func testAccBigtableInstance_noAllowDestroy (instanceName string , numNodes int ) string {
359+ return fmt .Sprintf (`
360+ resource "google_bigtable_instance" "instance" {
361+ name = "%s"
362+ cluster {
363+ cluster_id = "%s"
364+ zone = "us-central1-b"
365+ num_nodes = %d
366+ storage_type = "HDD"
367+ }
368+ }
369+ ` , instanceName , instanceName , numNodes )
370+ }
0 commit comments