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 3d8c9b5
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 91 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
129 changes: 127 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,131 @@ 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"
}
}
}
}
resource "google_sql_database_instance" "instance" {
name = "cloudrun-sql%{random_suffix}"
region = "us-east1"
settings {
tier = "D0"
}
}
`, context)
}

func TestAccCloudRunService_cloudRunServiceNoauthExample(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_cloudRunServiceNoauthExample(context),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCloudRunService_cloudRunServiceNoauthExample(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"
}
}
}
}
data "google_iam_policy" "noauth" {
binding {
role = "roles/run.invoker"
members = [
"allUsers",
]
}
}
resource "google_cloud_run_service_iam_policy" "noauth" {
location = google_cloud_run_service.default.location
project = google_cloud_run_service.default.project
service = google_cloud_run_service.default.name
policy_data = data.google_iam_policy.noauth.policy_data
}
`, 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)
}
Loading

0 comments on commit 3d8c9b5

Please sign in to comment.