1+ package cloudrunv2_test
2+
3+ {{ if ne $.TargetVersionName "ga" }}
4+ import (
5+ "fmt"
6+ "log"
7+ "strconv"
8+ "strings"
9+ "testing"
10+ "time"
11+
12+ "github.com/hashicorp/terraform-plugin-testing/helper/resource"
13+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
14+ "github.com/hashicorp/terraform-plugin-testing/terraform"
15+
16+ "github.com/hashicorp/terraform-provider-google/google/acctest"
17+ "github.com/hashicorp/terraform-provider-google/google/envvar"
18+ "github.com/hashicorp/terraform-provider-google/google/tpgresource"
19+ transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
20+
21+ "google.golang.org/api/googleapi"
22+ )
23+
24+ var (
25+ _ = fmt.Sprintf
26+ _ = log.Print
27+ _ = strconv.Atoi
28+ _ = strings.Trim
29+ _ = time.Now
30+ _ = resource.TestMain
31+ _ = terraform.NewState
32+ _ = envvar.TestEnvVar
33+ _ = tpgresource.SetLabels
34+ _ = transport_tpg.Config{}
35+ _ = googleapi.Error{}
36+ )
37+
38+ func TestAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_update(t *testing.T) {
39+ t.Parallel()
40+
41+ context := map[string]interface{}{
42+ "random_suffix": acctest.RandString(t, 10),
43+ }
44+
45+ acctest.VcrTest(t, resource.TestCase{
46+ PreCheck: func() { acctest.AccTestPreCheck(t) },
47+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
48+ CheckDestroy: testAccCheckCloudRunV2ServiceDestroyProducer(t),
49+ Steps: []resource.TestStep{
50+ {
51+ Config: testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_basic(context),
52+ },
53+ {
54+ ResourceName: "google_cloud_run_v2_service.default",
55+ ImportState: true,
56+ ImportStateVerify: true,
57+ ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
58+ },
59+ {
60+ Config: testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_update(context),
61+ ConfigPlanChecks: resource.ConfigPlanChecks{
62+ PreApply: []plancheck.PlanCheck{
63+ plancheck.ExpectResourceAction("google_cloud_run_v2_service.default", plancheck.ResourceActionUpdate),
64+ },
65+ },
66+ },
67+ {
68+ ResourceName: "google_cloud_run_v2_service.default",
69+ ImportState: true,
70+ ImportStateVerify: true,
71+ ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
72+ },
73+ },
74+ })
75+ }
76+
77+ func testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_basic(context map[string]interface{}) string {
78+ return acctest.Nprintf(`
79+ resource "google_storage_bucket" "sourcebucket" {
80+ provider = google-beta
81+ name = "${data.google_project.project.project_id}-tf-test-gcf-source%{random_suffix}" # Every bucket name must be globally unique
82+ location = "US"
83+ uniform_bucket_level_access = true
84+ }
85+
86+ resource "google_storage_bucket_object" "source_tar" {
87+ provider = google-beta
88+ name = "function-source.zip"
89+ bucket = google_storage_bucket.sourcebucket.name
90+ source = "./test-fixtures/cr-zip-nodejs-hello.tar.gz"
91+ }
92+
93+ resource "google_cloud_run_v2_service" "default" {
94+ provider = google-beta
95+ name = "tf-test-cloudrun-zip-service%{random_suffix}"
96+ location = "us-central1"
97+ deletion_protection = false
98+
99+ template {
100+ containers {
101+ image = "scratch"
102+ base_image_uri = "us-central1-docker.pkg.dev/serverless-runtimes/google-24-full/runtimes/nodejs24"
103+ command = ["node"]
104+ args = ["index.js"]
105+ source_code {
106+ cloud_storage_source {
107+ bucket = google_storage_bucket.sourcebucket.name
108+ object = google_storage_bucket_object.source_tar.name
109+ generation = google_storage_bucket_object.source_tar.generation
110+ }
111+ }
112+ }
113+ }
114+ }
115+
116+ data "google_project" "project" {
117+ provider = google-beta
118+ }
119+ `, context)
120+ }
121+
122+ func testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_update(context map[string]interface{}) string {
123+ return acctest.Nprintf(`
124+ resource "google_storage_bucket" "sourcebucket" {
125+ provider = google-beta
126+ name = "${data.google_project.project.project_id}-tf-test-gcf-source%{random_suffix}" # Every bucket name must be globally unique
127+ location = "US"
128+ uniform_bucket_level_access = true
129+ }
130+
131+ resource "google_storage_bucket_object" "source_tar" {
132+ provider = google-beta
133+ name = "function-source.zip"
134+ bucket = google_storage_bucket.sourcebucket.name
135+ source = "./test-fixtures/cr-zip-py-hello.tar.gz"
136+ }
137+
138+ resource "google_cloud_run_v2_service" "default" {
139+ provider = google-beta
140+ name = "tf-test-cloudrun-zip-service%{random_suffix}"
141+ location = "us-central1"
142+ deletion_protection = false
143+
144+ template {
145+ containers {
146+ image = "scratch"
147+ base_image_uri = "us-central1-docker.pkg.dev/serverless-runtimes/google-22-full/runtimes/python313"
148+ command = ["python"]
149+ args = ["main.py"]
150+ source_code {
151+ cloud_storage_source {
152+ bucket = google_storage_bucket.sourcebucket.name
153+ object = google_storage_bucket_object.source_tar.name
154+ generation = google_storage_bucket_object.source_tar.generation
155+ }
156+ }
157+ }
158+ }
159+ }
160+
161+ data "google_project" "project" {
162+ provider = google-beta
163+ }
164+ `, context)
165+ }
166+ {{ end }}
0 commit comments