Skip to content

Commit 04f73ae

Browse files
committed
add test case
1 parent fc9ac30 commit 04f73ae

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

mmv1/third_party/terraform/services/cloudfunctions2/resource_cloudfunctions2_function_test.go

+81
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,84 @@ output "object_gen_eq_storage_source_gen" {
561561
}
562562
`, context)
563563
}
564+
565+
func TestAccCloudFunctions2Function_binAuthPolicy(t *testing.T) {
566+
t.Parallel()
567+
568+
context := map[string]interface{}{
569+
"zip_path": "./test-fixtures/function-source.zip",
570+
"random_suffix": acctest.RandString(t, 10),
571+
}
572+
573+
acctest.VcrTest(t, resource.TestCase{
574+
PreCheck: func() { acctest.AccTestPreCheck(t) },
575+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
576+
CheckDestroy: testAccCheckCloudfunctions2functionDestroyProducer(t),
577+
Steps: []resource.TestStep{
578+
{
579+
Config: testAccCloudfunctions2function_binAuthz(context),
580+
Check: resource.ComposeTestCheckFunc(
581+
resource.TestCheckOutput("binary_authorization_policy_eq", "true"),
582+
),
583+
},
584+
},
585+
})
586+
}
587+
588+
func testAccCloudfunctions2function_binAuthz(context map[string]interface{}) string {
589+
return acctest.Nprintf(`
590+
resource "google_storage_bucket" "bucket" {
591+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
592+
location = "US"
593+
uniform_bucket_level_access = true
594+
}
595+
596+
resource "google_storage_bucket_object" "object" {
597+
name = "function-source.zip"
598+
bucket = google_storage_bucket.bucket.name
599+
source = "%{zip_path}"
600+
}
601+
602+
resource "google_binary_authorization_policy" "policy" {
603+
default_admission_rule {
604+
evaluation_mode = "ALWAYS_ALLOW"
605+
enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG"
606+
}
607+
}
608+
609+
resource "google_cloudfunctions2_function" "terraform-test2" {
610+
depends_on = [
611+
google_binary_authorization_policy.policy
612+
]
613+
name = "tf-test-test-function%{random_suffix}"
614+
location = "us-central1"
615+
description = "a new function"
616+
labels = {
617+
env = "test"
618+
}
619+
620+
build_config {
621+
runtime = "nodejs18"
622+
entry_point = "helloHttp"
623+
source {
624+
storage_source {
625+
bucket = google_storage_bucket.bucket.name
626+
object = google_storage_bucket_object.object.name
627+
generation = google_storage_bucket_object.object.generation
628+
}
629+
}
630+
}
631+
632+
service_config {
633+
max_instance_count = 1
634+
available_memory = "1536Mi"
635+
timeout_seconds = 30
636+
binary_authorization_policy = "default"
637+
}
638+
}
639+
640+
output "binary_authorization_policy_eq" {
641+
value = google_cloudfunctions2_function.terraform-test2.service_config.0.binary_authorization_policy == "default"
642+
}
643+
`, context)
644+
}

0 commit comments

Comments
 (0)