Skip to content

Added VCP test for IAP integration in cloudrun v1 #13574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mmv1/products/cloudrun/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ examples:
cloud_run_service_name: 'cloudrun-srv'
test_env_vars:
project: 'PROJECT_NAME'
- name: 'cloud_run_service_iap'
primary_resource_id: 'default'
primary_resource_name: 'fmt.Sprintf("tf-test-cloudrun-srv%s", context["random_suffix"])'
min_version: 'beta'
vars:
cloud_run_service_name: 'cloudrun-srv'
test_env_vars:
project: 'PROJECT_NAME'
virtual_fields:
- name: 'autogenerate_revision_name'
description: |
Expand Down
21 changes: 21 additions & 0 deletions mmv1/templates/terraform/examples/cloud_run_service_iap.tf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "google_cloud_run_service" "{{$.PrimaryResourceId}}" {
provider = google-beta
name = "{{index $.Vars "cloud_run_service_name"}}"
location = "us-central1"

metadata {
annotations = {
"run.googleapis.com/launch-stage" = "BETA"
"run.googleapis.com/iap-enabled": true
}
}

template {
spec {
containers {
image = "gcr.io/cloudrun/hello"
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -1593,3 +1593,90 @@ resource "google_cloud_run_service" "default" {
}
`, name, project)
}

{{ if ne $.TargetVersionName `ga` -}}
func TestAccCloudRunService_cloudRunServiceIap_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project": envvar.GetTestProjectFromEnv(),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckCloudRunServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCloudRunService_cloudRunServiceIapEnabled(context),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "name"},
},
{
Config: testAccCloudRunService_cloudRunServiceIapDisabled(context),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "name"},
},
},
})
}

func testAccCloudRunService_cloudRunServiceIapEnabled(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-srv%{random_suffix}"
location = "us-central1"

metadata {
annotations = {
"run.googleapis.com/iap-enabled": true
"run.googleapis.com/launch-stage" = "BETA"
}
}

template {
spec {
containers {
image = "gcr.io/cloudrun/hello"
}
}
}
}
`, context)
}

func testAccCloudRunService_cloudRunServiceIapDisabled(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_cloud_run_service" "default" {
provider = google-beta
name = "tf-test-cloudrun-srv%{random_suffix}"
location = "us-central1"

metadata {
annotations = {
"run.googleapis.com/iap-enabled": false
}
}

template {
spec {
containers {
image = "gcr.io/cloudrun/hello"
}
}
}
}
`, context)
}
{{- end }}

Loading