Skip to content

Added VCP test for IAP integration in cloudrun v1 #9751

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,57 @@ resource "google_cloud_run_service" "default" {
`, context)
}

func TestAccCloudRunService_cloudRunServiceIapExample(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_cloudRunServiceIapExample(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_cloudRunServiceIapExample(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/launch-stage" = "BETA"
"run.googleapis.com/iap-enabled": true
}
}

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

func testAccCheckCloudRunServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1587,3 +1587,87 @@ resource "google_cloud_run_service" "default" {
}
`, name, project)
}

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)
}
25 changes: 25 additions & 0 deletions website/docs/r/cloud_run_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,31 @@ resource "google_cloud_run_service" "default" {
}
}
```
## Example Usage - Cloud Run Service Iap


```hcl
resource "google_cloud_run_service" "default" {
provider = google-beta
name = "cloudrun-srv"
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"
}
}
}
}
```

## Argument Reference

Expand Down