From 77041bfd26766336f1c2a47818425c46712e5b7a Mon Sep 17 00:00:00 2001 From: Benjamin Kaplan Date: Wed, 20 Mar 2024 12:55:05 -0700 Subject: [PATCH 1/3] Add nfs support to cloudrun v1 services. This is already supported in v2. --- mmv1/products/cloudrun/Service.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mmv1/products/cloudrun/Service.yaml b/mmv1/products/cloudrun/Service.yaml index 255447328bd4..86114149d106 100644 --- a/mmv1/products/cloudrun/Service.yaml +++ b/mmv1/products/cloudrun/Service.yaml @@ -875,6 +875,28 @@ properties: Driver-specific attributes. The following options are supported for available drivers: * gcsfuse.run.googleapis.com * bucketName: The name of the Cloud Storage Bucket that backs this volume. The Cloud Run Service identity must have access to this bucket. + - !ruby/object:Api::Type::NestedObject + name: nfs + description: |- + A filesystem backed by a Network File System share. This filesystem requires the + run.googleapis.com/execution-environment annotation to be set to "gen2" and + run.googleapis.com/launch-stage set to "BETA" or "ALPHA". + min_version: beta + properties: + - !ruby/object:Api::Type::String + name: server + required: true + description: |- + IP address or hostname of the NFS server + - !ruby/object:Api::Type::String + name: path + required: true + description: |- + Path exported by the NFS server + - !ruby/object:Api::Type::Boolean + name: readOnly + description: |- + If true, mount the NFS volume as read only in all mounts. Defaults to false. - !ruby/object:Api::Type::Enum name: servingState deprecation_message: >- From b2f474dd034e5a0247a8e91f192c3a11764de146 Mon Sep 17 00:00:00 2001 From: Benjamin Kaplan Date: Mon, 25 Mar 2024 13:23:15 -0700 Subject: [PATCH 2/3] adding test for nfs v1 --- .../resource_cloud_run_service_test.go.erb | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb b/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb index e73d70762477..956409811a7e 100644 --- a/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb +++ b/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb @@ -1273,6 +1273,28 @@ func TestAccCloudRunService_csiVolume(t *testing.T) { }, }) } +func TestAccCloudRunService_nfsVolume(t *testing.T) { + t.Parallel() + + project := envvar.GetTestProjectFromEnv() + suffix := acctest.RandString(t, 6) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudRunService_cloudRunServiceWithFilestoreVolume(suffix, project), + }, + { + ResourceName: "google_cloud_run_service.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "status.0.conditions"}, + }, + }, + }) +} func testAccCloudRunService_cloudRunServiceWithEmptyDirVolume(name, project string) string { @@ -1366,4 +1388,85 @@ resource "google_cloud_run_service" "default" { `, name, project) } +func testAccCloudRunService_cloudRunServiceWithFilestoreVolume(suffix, project string) string { + return acctest.Nprintf(` +resource "google_compute_subnetwork" "test_subnet" { + provider = google-beta + name = "tf-test-cloudrun-subnet-%{suffix}" + ip_cidr_range = "10.2.0.0/24" + region = "us-central1" + network = google_compute_network.test_network.id +} +resource "google_compute_network" "test_network" { + provider = google-beta + name = "tf-test-cloudrun-network-%{suffix}" + auto_create_subnetworks = false +} +resource "google_filestore_instance" "nfs_share" { + provider = google-beta + name = "tf-test-cloudrun-fstore-%{suffix}" + zone = "us-central1-b" + tier = "BASIC_HDD" + + file_shares { + capacity_gb = 1024 + name = "share1" + } + + networks { + network = "${google_compute_network.test_network.name}" + modes = ["MODE_IPV4"] + } +} +resource "google_cloud_run_service" "default" { + provider = google-beta + name = "tf-test-cloudrun-svc-%{suffix}" + location = "us-central1" + + metadata { + namespace = "%{project}" + annotations = { + generated-by = "magic-modules" + "run.googleapis.com/launch-stage" = "BETA" + } + } + + template { + metadata { + annotations = { + "run.googleapis.com/execution-environment" = "gen2" + "run.googleapis.com/network-interfaces" = "[{\"network\": \"${google_compute_network.test_network.id}\", \"subnetwork\": \"${google_compute_subnetwork.test_subnet.name}\"}]" + "run.googleapis.com/vpc-access-egress" = "private-ranges-only" + } + } + spec { + containers { + image = "gcr.io/cloudrun/hello" + volume_mounts { + name = "vol1" + mount_path = "/mnt/vol1" + } + } + volumes { + name = "vol1" + nfs { + server = google_filestore_instance.nfs_share.networks[0].ip_addresses[0] + path = "/${google_filestore_instance.nfs_share.file_shares[0].name}" + } + } + } + } + + lifecycle { + ignore_changes = [ + metadata.0.annotations, + ] + } +} +`, map[string]interface{}{ + "suffix": suffix, + "project": project, +}) +} + <% end -%> From 76b50f2eca5c13565d1a7c95444e96dc91d55343 Mon Sep 17 00:00:00 2001 From: Benjamin Kaplan Date: Tue, 26 Mar 2024 12:41:38 -0700 Subject: [PATCH 3/3] Revert "adding test for nfs v1" This reverts commit b2f474dd034e5a0247a8e91f192c3a11764de146. --- .../resource_cloud_run_service_test.go.erb | 103 ------------------ 1 file changed, 103 deletions(-) diff --git a/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb b/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb index 956409811a7e..e73d70762477 100644 --- a/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb +++ b/mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.erb @@ -1273,28 +1273,6 @@ func TestAccCloudRunService_csiVolume(t *testing.T) { }, }) } -func TestAccCloudRunService_nfsVolume(t *testing.T) { - t.Parallel() - - project := envvar.GetTestProjectFromEnv() - suffix := acctest.RandString(t, 6) - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudRunService_cloudRunServiceWithFilestoreVolume(suffix, project), - }, - { - ResourceName: "google_cloud_run_service.default", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "status.0.conditions"}, - }, - }, - }) -} func testAccCloudRunService_cloudRunServiceWithEmptyDirVolume(name, project string) string { @@ -1388,85 +1366,4 @@ resource "google_cloud_run_service" "default" { `, name, project) } -func testAccCloudRunService_cloudRunServiceWithFilestoreVolume(suffix, project string) string { - return acctest.Nprintf(` -resource "google_compute_subnetwork" "test_subnet" { - provider = google-beta - name = "tf-test-cloudrun-subnet-%{suffix}" - ip_cidr_range = "10.2.0.0/24" - region = "us-central1" - network = google_compute_network.test_network.id -} -resource "google_compute_network" "test_network" { - provider = google-beta - name = "tf-test-cloudrun-network-%{suffix}" - auto_create_subnetworks = false -} -resource "google_filestore_instance" "nfs_share" { - provider = google-beta - name = "tf-test-cloudrun-fstore-%{suffix}" - zone = "us-central1-b" - tier = "BASIC_HDD" - - file_shares { - capacity_gb = 1024 - name = "share1" - } - - networks { - network = "${google_compute_network.test_network.name}" - modes = ["MODE_IPV4"] - } -} -resource "google_cloud_run_service" "default" { - provider = google-beta - name = "tf-test-cloudrun-svc-%{suffix}" - location = "us-central1" - - metadata { - namespace = "%{project}" - annotations = { - generated-by = "magic-modules" - "run.googleapis.com/launch-stage" = "BETA" - } - } - - template { - metadata { - annotations = { - "run.googleapis.com/execution-environment" = "gen2" - "run.googleapis.com/network-interfaces" = "[{\"network\": \"${google_compute_network.test_network.id}\", \"subnetwork\": \"${google_compute_subnetwork.test_subnet.name}\"}]" - "run.googleapis.com/vpc-access-egress" = "private-ranges-only" - } - } - spec { - containers { - image = "gcr.io/cloudrun/hello" - volume_mounts { - name = "vol1" - mount_path = "/mnt/vol1" - } - } - volumes { - name = "vol1" - nfs { - server = google_filestore_instance.nfs_share.networks[0].ip_addresses[0] - path = "/${google_filestore_instance.nfs_share.file_shares[0].name}" - } - } - } - } - - lifecycle { - ignore_changes = [ - metadata.0.annotations, - ] - } -} -`, map[string]interface{}{ - "suffix": suffix, - "project": project, -}) -} - <% end -%>