88 "testing"
99
1010 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
1112 "github.com/hashicorp/terraform-plugin-testing/terraform"
1213 "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
1314 "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
@@ -24,7 +25,48 @@ func TestAccComputeSecurityPolicy_basic(t *testing.T) {
2425 CheckDestroy : testAccCheckComputeSecurityPolicyDestroyProducer (t ),
2526 Steps : []resource.TestStep {
2627 {
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+ ),
2870 },
2971 {
3072 ResourceName : "google_compute_security_policy.policy" ,
@@ -214,7 +256,7 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
214256 CheckDestroy : testAccCheckComputeSecurityPolicyDestroyProducer (t ),
215257 Steps : []resource.TestStep {
216258 {
217- Config : testAccComputeSecurityPolicy_basic (spName ),
259+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
218260 },
219261 {
220262 ResourceName : "google_compute_security_policy.policy" ,
@@ -256,7 +298,7 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
256298 ImportStateVerify : true ,
257299 },
258300 {
259- Config : testAccComputeSecurityPolicy_basic (spName ),
301+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
260302 },
261303 {
262304 ResourceName : "google_compute_security_policy.policy" ,
@@ -528,7 +570,7 @@ func TestAccComputeSecurityPolicy_withRecaptchaOptionsConfig(t *testing.T) {
528570 CheckDestroy : testAccCheckComputeSecurityPolicyDestroyProducer (t ),
529571 Steps : []resource.TestStep {
530572 {
531- Config : testAccComputeSecurityPolicy_basic (spName ),
573+ Config : testAccComputeSecurityPolicy_basic (spName , "CLOUD_ARMOR" ),
532574 },
533575 {
534576 ResourceName : "google_compute_security_policy.policy" ,
@@ -776,14 +818,14 @@ func testAccCheckComputeSecurityPolicyDestroyProducer(t *testing.T) func(s *terr
776818 }
777819}
778820
779- func testAccComputeSecurityPolicy_basic (spName string ) string {
821+ func testAccComputeSecurityPolicy_basic (spName , policyType string ) string {
780822 return fmt .Sprintf (`
781823resource "google_compute_security_policy" "policy" {
782824 name = "%s"
783825 description = "basic security policy"
784- type = "CLOUD_ARMOR "
826+ type = "%s "
785827}
786- ` , spName )
828+ ` , spName , policyType )
787829}
788830
789831func testAccComputeSecurityPolicy_withRule (spName string ) string {
0 commit comments