diff --git a/google/iam_cloud_run_service_generated_test.go b/google/iam_cloud_run_service_generated_test.go index 20b37123bb1..230a018f23b 100644 --- a/google/iam_cloud_run_service_generated_test.go +++ b/google/iam_cloud_run_service_generated_test.go @@ -28,7 +28,7 @@ func TestAccCloudRunServiceIamBindingGenerated(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(10), "role": "roles/viewer", - "namespace": getTestProjectFromEnv(), + "project": getTestProjectFromEnv(), } resource.Test(t, resource.TestCase{ @@ -64,7 +64,7 @@ func TestAccCloudRunServiceIamMemberGenerated(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(10), "role": "roles/viewer", - "namespace": getTestProjectFromEnv(), + "project": getTestProjectFromEnv(), } resource.Test(t, resource.TestCase{ @@ -91,7 +91,7 @@ func TestAccCloudRunServiceIamPolicyGenerated(t *testing.T) { context := map[string]interface{}{ "random_suffix": acctest.RandString(10), "role": "roles/viewer", - "namespace": getTestProjectFromEnv(), + "project": getTestProjectFromEnv(), } resource.Test(t, resource.TestCase{ @@ -118,7 +118,7 @@ resource "google_cloud_run_service" "default" { location = "us-central1" metadata { - namespace = "%{namespace}" + namespace = "" } template { @@ -152,7 +152,7 @@ resource "google_cloud_run_service" "default" { location = "us-central1" metadata { - namespace = "%{namespace}" + namespace = "" } template { @@ -192,7 +192,7 @@ resource "google_cloud_run_service" "default" { location = "us-central1" metadata { - namespace = "%{namespace}" + namespace = "" } template { @@ -226,7 +226,7 @@ resource "google_cloud_run_service" "default" { location = "us-central1" metadata { - namespace = "%{namespace}" + namespace = "" } template { diff --git a/google/resource_cloud_run_service_generated_test.go b/google/resource_cloud_run_service_generated_test.go index b175d8a58f9..1c978c69159 100644 --- a/google/resource_cloud_run_service_generated_test.go +++ b/google/resource_cloud_run_service_generated_test.go @@ -28,7 +28,7 @@ func TestAccCloudRunService_cloudRunServiceBasicExample(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "namespace": getTestProjectFromEnv(), + "project": getTestProjectFromEnv(), "random_suffix": acctest.RandString(10), } @@ -56,7 +56,7 @@ resource "google_cloud_run_service" "default" { location = "us-central1" metadata { - namespace = "%{namespace}" + namespace = "" } template { @@ -75,6 +75,73 @@ resource "google_cloud_run_service" "default" { `, context) } +func TestAccCloudRunService_cloudRunServiceSqlExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project": getTestProjectFromEnv(), + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCloudRunServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCloudRunService_cloudRunServiceSqlExample(context), + }, + { + ResourceName: "google_cloud_run_service.default", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCloudRunService_cloudRunServiceSqlExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_cloud_run_service" "default" { + name = "tftest-cloudrun%{random_suffix}" + location = "us-central1" + + metadata { + namespace = "%{project}" + } + + template { + spec { + containers { + image = "gcr.io/cloudrun/hello" + } + } + + metadata { + annotations = { + "autoscaling.knative.dev/maxScale" = "1000" + "run.googleapis.com/cloudsql-instances" = "%{project}:us-central1:${google_sql_database_instance.instance.name}" + "run.googleapis.com/client-name" = "cloud-console" + } + } + } + + traffic { + percent = 100 + latest_revision = true + } +} + +resource "google_sql_database_instance" "instance" { + name = "cloudrun-sql%{random_suffix}" + region = "us-east1" + settings { + tier = "D0" + } +} +`, context) +} + func testAccCheckCloudRunServiceDestroy(s *terraform.State) error { for name, rs := range s.RootModule().Resources { if rs.Type != "google_cloud_run_service" { diff --git a/google/resource_cloud_run_service_test.go b/google/resource_cloud_run_service_test.go index 86a91ca355e..08abb9ed60d 100644 --- a/google/resource_cloud_run_service_test.go +++ b/google/resource_cloud_run_service_test.go @@ -40,29 +40,6 @@ func TestAccCloudRunService_cloudRunServiceUpdate(t *testing.T) { }) } -func TestAccCloudRunService_cloudRunServiceSql(t *testing.T) { - t.Parallel() - - project := getTestProjectFromEnv() - name := "tftest-cloudrun-" + acctest.RandString(6) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCloudRunService_cloudRunServiceSql(name, project), - }, - { - ResourceName: "google_cloud_run_service.default", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "status.0.conditions"}, - }, - }, - }) -} - func testAccCloudRunService_cloudRunServiceUpdate(name, project, concurrency string) string { return fmt.Sprintf(` resource "google_cloud_run_service" "default" { @@ -90,61 +67,3 @@ resource "google_cloud_run_service" "default" { } `, name, project, concurrency) } - -func testAccCloudRunService_cloudRunServiceSql(name, project string) string { - return fmt.Sprintf(` -data "google_project" "project" {} - -resource "google_sql_database_instance" "instance" { - name = "tf-test-%s" - region = "us-east1" - settings { - tier = "D0" - } -} - -resource "google_cloud_run_service" "default" { - location = "us-east1" - name = "%s" - - metadata { - namespace = "%s" - labels = { - "cloud.googleapis.com/location" = "us-east1" - "foo" = "bar" - } - } - - template { - metadata { - annotations = { - "autoscaling.knative.dev/maxScale" = "1000" - "run.googleapis.com/cloudsql-instances" = "%s:us-east1:${google_sql_database_instance.instance.name}" - "run.googleapis.com/client-name" = "cloud-console" - } - } - - spec { - service_account_name = "${data.google_project.project.number}-compute@developer.gserviceaccount.com" - - containers { - image = "gcr.io/cloudrun/hello" - args = ["arrg2", "pirate"] - resources { - limits = { - cpu = "1000m" - memory = "256Mi" - } - } - } - container_concurrency = 10 - } - } - - traffic { - percent = 100 - latest_revision = true - } -} -`, acctest.RandString(6), name, project, project) -} diff --git a/website/docs/r/cloud_run_service.html.markdown b/website/docs/r/cloud_run_service.html.markdown index 9163e794515..6ddc1741e4b 100644 --- a/website/docs/r/cloud_run_service.html.markdown +++ b/website/docs/r/cloud_run_service.html.markdown @@ -52,6 +52,37 @@ To get more information about Service, see: ## Example Usage - Cloud Run Service Basic +```hcl +resource "google_cloud_run_service" "default" { + name = "tftest-cloudrun" + location = "us-central1" + + metadata { + namespace = "" + } + + template { + spec { + containers { + image = "gcr.io/cloudrun/hello" + } + } + } + + traffic { + percent = 100 + latest_revision = true + } +} +``` +
+ + Open in Cloud Shell + +
+## Example Usage - Cloud Run Service Sql + + ```hcl resource "google_cloud_run_service" "default" { name = "tftest-cloudrun" @@ -67,6 +98,14 @@ resource "google_cloud_run_service" "default" { image = "gcr.io/cloudrun/hello" } } + + metadata { + annotations = { + "autoscaling.knative.dev/maxScale" = "1000" + "run.googleapis.com/cloudsql-instances" = "my-project-name:us-central1:${google_sql_database_instance.instance.name}" + "run.googleapis.com/client-name" = "cloud-console" + } + } } traffic { @@ -74,6 +113,14 @@ resource "google_cloud_run_service" "default" { latest_revision = true } } + +resource "google_sql_database_instance" "instance" { + name = "cloudrun-sql" + region = "us-east1" + settings { + tier = "D0" + } +} ``` ## Argument Reference