Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions mmv1/products/cloudrunv2/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ examples:
cloud_run_service_name: 'cloudrun-iap-service'
ignore_read_extra:
- 'deletion_protection'
- name: 'cloudrunv2_service_zip_deploy'
primary_resource_id: 'default'
primary_resource_name: 'fmt.Sprintf("tf-test-cloudrun-service%s", context["random_suffix"])'
min_version: 'beta'
vars:
cloud_run_service_name: 'cloudrun-zip-service'
targz_path: './test-fixtures/function-source.tar.gz'
ignore_read_extra:
- 'deletion_protection'
virtual_fields:
- name: 'deletion_protection'
description: |
Expand Down Expand Up @@ -813,6 +822,33 @@ properties:
description: |-
Source code location of the image.
output: true
- name: 'sourceCode'
type: NestedObject
description: |-
Location of the source.
min_version: 'beta'
properties:
- name: 'cloudStorageSource'
type: NestedObject
description: |-
Cloud Storage source.
exactly_one_of:
- 'cloud_storage_source'
properties:
- name: 'bucket'
type: String
description: |-
The Cloud Storage bucket name.
required: true
- name: 'object'
type: String
description: |-
The Cloud Storage object name.
required: true
- name: 'generation'
type: String
description: |-
The Cloud Storage object generation. The is an int64 value. As with most Google APIs, its JSON representation will be a string instead of an integer.
- name: 'volumes'
type: Array
description: |-
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "google_storage_bucket" "sourcebucket" {
provider = google-beta
name = "${data.google_project.project.project_id}-tf-test-gcf-source%{random_suffix}" # Every bucket name must be globally unique
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "source_tar" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.sourcebucket.name
source = "./test-fixtures/cr-zip-nodejs-hello.tar.gz"
}

resource "google_cloud_run_v2_service" "{{$.PrimaryResourceId}}" {
provider = google-beta
name = "{{index $.Vars "cloud_run_service_name"}}"
location = "us-central1"
deletion_protection = false

template {
containers {
image = "scratch"
base_image_uri = "us-central1-docker.pkg.dev/serverless-runtimes/google-24-full/runtimes/nodejs24"
command = ["node"]
args = ["index.js"]
source_code {
cloud_storage_source {
bucket = google_storage_bucket.sourcebucket.name
object = google_storage_bucket_object.source_tar.name
generation = google_storage_bucket_object.source_tar.generation
}
}
}
}
}

data "google_project" "project" {
provider = google-beta
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package cloudrunv2_test

{{ if ne $.TargetVersionName "ga" }}
import (
"fmt"
"log"
"strconv"
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"

"google.golang.org/api/googleapi"
)

var (
_ = fmt.Sprintf
_ = log.Print
_ = strconv.Atoi
_ = strings.Trim
_ = time.Now
_ = resource.TestMain
_ = terraform.NewState
_ = envvar.TestEnvVar
_ = tpgresource.SetLabels
_ = transport_tpg.Config{}
_ = googleapi.Error{}
)

func TestAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckCloudRunV2ServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_basic(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
},
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_update(context),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("google_cloud_run_v2_service.default", plancheck.ResourceActionUpdate),
},
},
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
},
},
})
}

func testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_storage_bucket" "sourcebucket" {
provider = google-beta
name = "${data.google_project.project.project_id}-tf-test-gcf-source%{random_suffix}" # Every bucket name must be globally unique
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "source_tar" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.sourcebucket.name
source = "./test-fixtures/cr-zip-nodejs-hello.tar.gz"
}

resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-zip-service%{random_suffix}"
location = "us-central1"
deletion_protection = false

template {
containers {
image = "scratch"
base_image_uri = "us-central1-docker.pkg.dev/serverless-runtimes/google-24-full/runtimes/nodejs24"
command = ["node"]
args = ["index.js"]
source_code {
cloud_storage_source {
bucket = google_storage_bucket.sourcebucket.name
object = google_storage_bucket_object.source_tar.name
generation = google_storage_bucket_object.source_tar.generation
}
}
}
}
}

data "google_project" "project" {
provider = google-beta
}
`, context)
}

func testAccCloudRunV2Service_cloudrunv2ServiceZipDeployExample_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_storage_bucket" "sourcebucket" {
provider = google-beta
name = "${data.google_project.project.project_id}-tf-test-gcf-source%{random_suffix}" # Every bucket name must be globally unique
location = "US"
uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "source_tar" {
provider = google-beta
name = "function-source.zip"
bucket = google_storage_bucket.sourcebucket.name
source = "./test-fixtures/cr-zip-py-hello.tar.gz"
}

resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-zip-service%{random_suffix}"
location = "us-central1"
deletion_protection = false

template {
containers {
image = "scratch"
base_image_uri = "us-central1-docker.pkg.dev/serverless-runtimes/google-22-full/runtimes/python313"
command = ["python"]
args = ["main.py"]
source_code {
cloud_storage_source {
bucket = google_storage_bucket.sourcebucket.name
object = google_storage_bucket_object.source_tar.name
generation = google_storage_bucket_object.source_tar.generation
}
}
}
}
}

data "google_project" "project" {
provider = google-beta
}
`, context)
}
{{ end }}
Binary file not shown.
Binary file not shown.
Loading