8
8
"testing"
9
9
10
10
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11
+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
11
12
"github.com/hashicorp/terraform-plugin-testing/terraform"
12
13
"github.com/hashicorp/terraform-provider-google/google/acctest"
13
14
"github.com/hashicorp/terraform-provider-google/google/envvar"
@@ -24,7 +25,48 @@ func TestAccComputeSecurityPolicy_basic(t *testing.T) {
24
25
CheckDestroy : testAccCheckComputeSecurityPolicyDestroyProducer (t ),
25
26
Steps : []resource.TestStep {
26
27
{
27
- Config : testAccComputeSecurityPolicy_basic (spName ),
28
+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
29
+ },
30
+ {
31
+ ResourceName : "google_compute_security_policy.policy" ,
32
+ ImportState : true ,
33
+ ImportStateVerify : true ,
34
+ },
35
+ },
36
+ })
37
+ }
38
+
39
+ func TestAccComputeSecurityPolicy_basicUpdate (t * testing.T ) {
40
+ t .Parallel ()
41
+
42
+ spName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
43
+
44
+ acctest .VcrTest (t , resource.TestCase {
45
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
46
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
47
+ CheckDestroy : testAccCheckComputeSecurityPolicyDestroyProducer (t ),
48
+ Steps : []resource.TestStep {
49
+ {
50
+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
51
+ Check : resource .ComposeTestCheckFunc (
52
+ resource .TestCheckResourceAttr ("google_compute_security_policy.policy" , "type" , "CLOUD_ARMOR" ),
53
+ ),
54
+ },
55
+ {
56
+ ResourceName : "google_compute_security_policy.policy" ,
57
+ ImportState : true ,
58
+ ImportStateVerify : true ,
59
+ },
60
+ {
61
+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR_EDGE" ),
62
+ ConfigPlanChecks : resource.ConfigPlanChecks {
63
+ PreApply : []plancheck.PlanCheck {
64
+ plancheck .ExpectResourceAction ("google_compute_security_policy.policy" , plancheck .ResourceActionDestroyBeforeCreate ),
65
+ },
66
+ },
67
+ Check : resource .ComposeTestCheckFunc (
68
+ resource .TestCheckResourceAttr ("google_compute_security_policy.policy" , "type" , "CLOUD_ARMOR_EDGE" ),
69
+ ),
28
70
},
29
71
{
30
72
ResourceName : "google_compute_security_policy.policy" ,
@@ -214,7 +256,7 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
214
256
CheckDestroy : testAccCheckComputeSecurityPolicyDestroyProducer (t ),
215
257
Steps : []resource.TestStep {
216
258
{
217
- Config : testAccComputeSecurityPolicy_basic (spName ),
259
+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
218
260
},
219
261
{
220
262
ResourceName : "google_compute_security_policy.policy" ,
@@ -256,7 +298,7 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
256
298
ImportStateVerify : true ,
257
299
},
258
300
{
259
- Config : testAccComputeSecurityPolicy_basic (spName ),
301
+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
260
302
},
261
303
{
262
304
ResourceName : "google_compute_security_policy.policy" ,
@@ -384,7 +426,7 @@ func TestAccComputeSecurityPolicy_withRecaptchaOptionsConfig(t *testing.T) {
384
426
CheckDestroy : testAccCheckComputeSecurityPolicyDestroyProducer (t ),
385
427
Steps : []resource.TestStep {
386
428
{
387
- Config : testAccComputeSecurityPolicy_basic (spName ),
429
+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
388
430
},
389
431
{
390
432
ResourceName : "google_compute_security_policy.policy" ,
@@ -632,14 +674,14 @@ func testAccCheckComputeSecurityPolicyDestroyProducer(t *testing.T) func(s *terr
632
674
}
633
675
}
634
676
635
- func testAccComputeSecurityPolicy_basic (spName string ) string {
677
+ func testAccComputeSecurityPolicy_basic (spName , policyType string ) string {
636
678
return fmt .Sprintf (`
637
679
resource "google_compute_security_policy" "policy" {
638
680
name = "%s"
639
681
description = "basic security policy"
640
- type = "CLOUD_ARMOR "
682
+ type = "%s "
641
683
}
642
- ` , spName )
684
+ ` , spName , policyType )
643
685
}
644
686
645
687
func testAccComputeSecurityPolicy_withRule (spName string ) string {
0 commit comments