Skip to content

Commit fec4a1e

Browse files
authored
Added VCP test for IAP integration in cloudrun v1 (#13574)
1 parent 3275fb5 commit fec4a1e

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

mmv1/products/cloudrun/Service.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ examples:
145145
cloud_run_service_name: 'cloudrun-srv'
146146
test_env_vars:
147147
project: 'PROJECT_NAME'
148+
- name: 'cloud_run_service_iap'
149+
primary_resource_id: 'default'
150+
primary_resource_name: 'fmt.Sprintf("tf-test-cloudrun-srv%s", context["random_suffix"])'
151+
min_version: 'beta'
152+
vars:
153+
cloud_run_service_name: 'cloudrun-srv'
154+
test_env_vars:
155+
project: 'PROJECT_NAME'
148156
virtual_fields:
149157
- name: 'autogenerate_revision_name'
150158
description: |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "google_cloud_run_service" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
name = "{{index $.Vars "cloud_run_service_name"}}"
4+
location = "us-central1"
5+
6+
metadata {
7+
annotations = {
8+
"run.googleapis.com/launch-stage" = "BETA"
9+
"run.googleapis.com/iap-enabled": true
10+
}
11+
}
12+
13+
template {
14+
spec {
15+
containers {
16+
image = "gcr.io/cloudrun/hello"
17+
}
18+
}
19+
}
20+
}
21+

mmv1/third_party/terraform/services/cloudrun/resource_cloud_run_service_test.go.tmpl

+87
Original file line numberDiff line numberDiff line change
@@ -1593,3 +1593,90 @@ resource "google_cloud_run_service" "default" {
15931593
}
15941594
`, name, project)
15951595
}
1596+
1597+
{{ if ne $.TargetVersionName `ga` -}}
1598+
func TestAccCloudRunService_cloudRunServiceIap_update(t *testing.T) {
1599+
t.Parallel()
1600+
1601+
context := map[string]interface{}{
1602+
"project": envvar.GetTestProjectFromEnv(),
1603+
"random_suffix": acctest.RandString(t, 10),
1604+
}
1605+
1606+
acctest.VcrTest(t, resource.TestCase{
1607+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1608+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
1609+
CheckDestroy: testAccCheckCloudRunServiceDestroyProducer(t),
1610+
Steps: []resource.TestStep{
1611+
{
1612+
Config: testAccCloudRunService_cloudRunServiceIapEnabled(context),
1613+
},
1614+
{
1615+
ResourceName: "google_cloud_run_service.default",
1616+
ImportState: true,
1617+
ImportStateVerify: true,
1618+
ImportStateVerifyIgnore: []string{"location", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "name"},
1619+
},
1620+
{
1621+
Config: testAccCloudRunService_cloudRunServiceIapDisabled(context),
1622+
},
1623+
{
1624+
ResourceName: "google_cloud_run_service.default",
1625+
ImportState: true,
1626+
ImportStateVerify: true,
1627+
ImportStateVerifyIgnore: []string{"location", "metadata.0.annotations", "metadata.0.labels", "metadata.0.terraform_labels", "name"},
1628+
},
1629+
},
1630+
})
1631+
}
1632+
1633+
func testAccCloudRunService_cloudRunServiceIapEnabled(context map[string]interface{}) string {
1634+
return acctest.Nprintf(`
1635+
resource "google_cloud_run_service" "default" {
1636+
provider = google-beta
1637+
name = "tf-test-cloudrun-srv%{random_suffix}"
1638+
location = "us-central1"
1639+
1640+
metadata {
1641+
annotations = {
1642+
"run.googleapis.com/iap-enabled": true
1643+
"run.googleapis.com/launch-stage" = "BETA"
1644+
}
1645+
}
1646+
1647+
template {
1648+
spec {
1649+
containers {
1650+
image = "gcr.io/cloudrun/hello"
1651+
}
1652+
}
1653+
}
1654+
}
1655+
`, context)
1656+
}
1657+
1658+
func testAccCloudRunService_cloudRunServiceIapDisabled(context map[string]interface{}) string {
1659+
return acctest.Nprintf(`
1660+
resource "google_cloud_run_service" "default" {
1661+
provider = google-beta
1662+
name = "tf-test-cloudrun-srv%{random_suffix}"
1663+
location = "us-central1"
1664+
1665+
metadata {
1666+
annotations = {
1667+
"run.googleapis.com/iap-enabled": false
1668+
}
1669+
}
1670+
1671+
template {
1672+
spec {
1673+
containers {
1674+
image = "gcr.io/cloudrun/hello"
1675+
}
1676+
}
1677+
}
1678+
}
1679+
`, context)
1680+
}
1681+
{{- end }}
1682+

0 commit comments

Comments
 (0)