Skip to content

Commit

Permalink
Add service mesh field to Cloud Run v2 Service (GoogleCloudPlatform#1…
Browse files Browse the repository at this point in the history
…1502)

Co-authored-by: Zhenhua Li <[email protected]>
  • Loading branch information
ian-mi and zli82016 authored Sep 3, 2024
1 parent b7381a6 commit bd724bd
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mmv1/products/cloudrunv2/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ examples:
ignore_read_extra:
- 'deletion_protection'

- !ruby/object:Provider::Terraform::Examples
name: 'cloudrunv2_service_mesh'
min_version: 'beta'
external_providers: ['time']
primary_resource_id: 'default'
primary_resource_name: "fmt.Sprintf(\"tf-test-cloudrun-service-%s\", context[\"random_suffix\"])"
vars:
cloud_run_service_name: 'cloudrun-service'
mesh_name: 'network-services-mesh'
ignore_read_extra:
- 'deletion_protection'

parameters:
- !ruby/object:Api::Type::String
name: 'location'
Expand Down Expand Up @@ -877,6 +889,16 @@ properties:
name: 'sessionAffinity'
description: |-
Enables session affinity. For more information, go to https://cloud.google.com/run/docs/configuring/session-affinity
- !ruby/object:Api::Type::NestedObject
name: 'serviceMesh'
min_version: beta
description: |-
Enables Cloud Service Mesh for this Revision.
properties:
- !ruby/object:Api::Type::String
name: 'mesh'
description: |-
The Mesh resource name. For more information see https://cloud.google.com/service-mesh/docs/reference/network-services/rest/v1/projects.locations.meshes#resource:-mesh.
- !ruby/object:Api::Type::Array
name: 'traffic'
description: |-
Expand Down
29 changes: 29 additions & 0 deletions mmv1/templates/terraform/examples/cloudrunv2_service_mesh.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "google_cloud_run_v2_service" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['cloud_run_service_name'] %>"
depends_on = [time_sleep.wait_for_mesh]
deletion_protection = false

location = "us-central1"
launch_stage = "BETA"

template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
service_mesh {
mesh = google_network_services_mesh.mesh.id
}
}
}

resource "time_sleep" "wait_for_mesh" {
depends_on = [google_network_services_mesh.mesh]

create_duration = "1m"
}

resource "google_network_services_mesh" "mesh" {
provider = google-beta
name = "<%= ctx[:vars]['mesh_name'] %>"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1076,3 +1076,124 @@ resource "google_cloud_run_v2_service" "default" {
`, context)
}
<% end -%>

<% unless version == 'ga' -%>
func TestAccCloudRunV2Service_cloudrunv2ServiceMeshUpdate(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),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccCheckCloudRunV2ServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceMesh(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location", "annotations", "labels", "terraform_labels", "launch_stage", "deletion_protection"},
},
{
Config: testAccCloudRunV2Service_cloudrunv2ServiceMeshUpdate(context),
},
{
ResourceName: "google_cloud_run_v2_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location", "annotations", "labels", "terraform_labels", "launch_stage", "deletion_protection"},
},
},
})
}

func testAccCloudRunV2Service_cloudrunv2ServiceMesh(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-service%{random_suffix}"
location = "us-central1"
deletion_protection = false
depends_on = [time_sleep.wait_for_mesh]
launch_stage = "BETA"
template {
containers {
name = "container-1"
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
service_mesh {
mesh = google_network_services_mesh.mesh.id
}
}
}

resource "time_sleep" "wait_for_mesh" {
depends_on = [
google_network_services_mesh.mesh,
google_network_services_mesh.new_mesh,
]

create_duration = "1m"
}

resource "google_network_services_mesh" "mesh" {
provider = google-beta
name = "tf-test-mesh%{random_suffix}"
}

resource "google_network_services_mesh" "new_mesh" {
provider = google-beta
name = "tf-test-new-mesh%{random_suffix}"
}
`, context)
}

func testAccCloudRunV2Service_cloudrunv2ServiceMeshUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_v2_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-service%{random_suffix}"
location = "us-central1"
deletion_protection = false
depends_on = [time_sleep.wait_for_mesh]
launch_stage = "BETA"
template {
containers {
name = "container-1"
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
service_mesh {
mesh = google_network_services_mesh.new_mesh.id
}
}
}

resource "time_sleep" "wait_for_mesh" {
depends_on = [
google_network_services_mesh.mesh,
google_network_services_mesh.new_mesh,
]

create_duration = "1m"
}

resource "google_network_services_mesh" "mesh" {
provider = google-beta
name = "tf-test-mesh%{random_suffix}"
}

resource "google_network_services_mesh" "new_mesh" {
provider = google-beta
name = "tf-test-new-mesh%{random_suffix}"
}
`, context)
}
<% end -%>

0 comments on commit bd724bd

Please sign in to comment.