Skip to content

Commit

Permalink
Move cloudrun sql test to examples
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
chrisst authored and modular-magician committed Dec 6, 2019
1 parent b848d23 commit 67f0e81
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 90 deletions.
14 changes: 7 additions & 7 deletions google/iam_cloud_run_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -118,7 +118,7 @@ resource "google_cloud_run_service" "default" {
location = "us-central1"
metadata {
namespace = "%{namespace}"
namespace = ""
}
template {
Expand Down Expand Up @@ -152,7 +152,7 @@ resource "google_cloud_run_service" "default" {
location = "us-central1"
metadata {
namespace = "%{namespace}"
namespace = ""
}
template {
Expand Down Expand Up @@ -192,7 +192,7 @@ resource "google_cloud_run_service" "default" {
location = "us-central1"
metadata {
namespace = "%{namespace}"
namespace = ""
}
template {
Expand Down Expand Up @@ -226,7 +226,7 @@ resource "google_cloud_run_service" "default" {
location = "us-central1"
metadata {
namespace = "%{namespace}"
namespace = ""
}
template {
Expand Down
71 changes: 69 additions & 2 deletions google/resource_cloud_run_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -56,7 +56,7 @@ resource "google_cloud_run_service" "default" {
location = "us-central1"
metadata {
namespace = "%{namespace}"
namespace = ""
}
template {
Expand All @@ -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" {
Expand Down
81 changes: 0 additions & 81 deletions google/resource_cloud_run_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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}[email protected]"
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)
}
47 changes: 47 additions & 0 deletions website/docs/r/cloud_run_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=cloud_run_service_sql&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Cloud Run Service Sql


```hcl
resource "google_cloud_run_service" "default" {
name = "tftest-cloudrun"
Expand All @@ -67,13 +98,29 @@ 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 {
percent = 100
latest_revision = true
}
}
resource "google_sql_database_instance" "instance" {
name = "cloudrun-sql"
region = "us-east1"
settings {
tier = "D0"
}
}
```

## Argument Reference
Expand Down

0 comments on commit 67f0e81

Please sign in to comment.