Skip to content

Commit d26c739

Browse files
modular-magicianRoger Martinez
andauthored
Add new sample for Cloud Run access control tutorial (#6205) (#4475)
* add erb and yaml * tf fmt * remove provider block * add extra region tag * remove primary_resource_type * add missing line from prev merge Co-authored-by: Roger Martinez <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Roger Martinez <[email protected]>
1 parent f7226a7 commit d26c739

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

.changelog/6205.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
google_cloud_run_service: add sample for cloud run access control
3+
```

google-beta/resource_cloud_run_service_generated_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,62 @@ resource "google_compute_global_forwarding_rule" "https_default" {
11341134
`, context)
11351135
}
11361136

1137+
func TestAccCloudRunService_cloudrunServiceAccessControlExample(t *testing.T) {
1138+
t.Parallel()
1139+
1140+
context := map[string]interface{}{
1141+
"random_suffix": randString(t, 10),
1142+
}
1143+
1144+
vcrTest(t, resource.TestCase{
1145+
PreCheck: func() { testAccPreCheck(t) },
1146+
Providers: testAccProviders,
1147+
CheckDestroy: testAccCheckCloudRunServiceDestroyProducer(t),
1148+
Steps: []resource.TestStep{
1149+
{
1150+
Config: testAccCloudRunService_cloudrunServiceAccessControlExample(context),
1151+
},
1152+
{
1153+
ResourceName: "google_cloud_run_service.default",
1154+
ImportState: true,
1155+
ImportStateVerify: true,
1156+
ImportStateVerifyIgnore: []string{"name", "location"},
1157+
},
1158+
},
1159+
})
1160+
}
1161+
1162+
func testAccCloudRunService_cloudrunServiceAccessControlExample(context map[string]interface{}) string {
1163+
return Nprintf(`
1164+
resource "google_cloud_run_service" "default" {
1165+
name = "tf-test-cloud-run-srv%{random_suffix}"
1166+
location = "us-central1"
1167+
1168+
template {
1169+
spec {
1170+
containers {
1171+
image = "gcr.io/cloudrun/hello"
1172+
}
1173+
}
1174+
}
1175+
1176+
traffic {
1177+
percent = 100
1178+
latest_revision = true
1179+
}
1180+
}
1181+
1182+
resource "google_cloud_run_service_iam_binding" "default" {
1183+
location = google_cloud_run_service.default.location
1184+
service = google_cloud_run_service.default.name
1185+
role = "roles/run.invoker"
1186+
members = [
1187+
"allUsers"
1188+
]
1189+
}
1190+
`, context)
1191+
}
1192+
11371193
func TestAccCloudRunService_cloudRunSystemPackagesExample(t *testing.T) {
11381194
t.Parallel()
11391195

0 commit comments

Comments
 (0)