Skip to content

Commit 8d17cf4

Browse files
FEAT: Add dependsOn support in cloudrunv2 worker pool (#15444) (#10970)
[upstream:81daec8c2844c8abfc213bf3b0a46a4ad79b05e6] Signed-off-by: Modular Magician <[email protected]>
1 parent 49fa798 commit 8d17cf4

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed

.changelog/15444.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudrunv2: added `depends_on` to `template.container` on `google_cloud_run_v2_worker_pool` resource
3+
```

google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ This field follows Kubernetes annotations' namespacing, limits, and rules.`,
116116
Type: schema.TypeString,
117117
},
118118
},
119+
"depends_on": {
120+
Type: schema.TypeList,
121+
Optional: true,
122+
ForceNew: true,
123+
Description: `Names of the containers that must start before this container.`,
124+
Elem: &schema.Schema{
125+
Type: schema.TypeString,
126+
},
127+
},
119128
"env": {
120129
Type: schema.TypeSet,
121130
Optional: true,
@@ -1887,6 +1896,7 @@ func flattenCloudRunV2WorkerPoolTemplateContainers(v interface{}, d *schema.Reso
18871896
"image": flattenCloudRunV2WorkerPoolTemplateContainersImage(original["image"], d, config),
18881897
"command": flattenCloudRunV2WorkerPoolTemplateContainersCommand(original["command"], d, config),
18891898
"args": flattenCloudRunV2WorkerPoolTemplateContainersArgs(original["args"], d, config),
1899+
"depends_on": flattenCloudRunV2WorkerPoolTemplateContainersDependsOn(original["dependsOn"], d, config),
18901900
"env": flattenCloudRunV2WorkerPoolTemplateContainersEnv(original["env"], d, config),
18911901
"resources": flattenCloudRunV2WorkerPoolTemplateContainersResources(original["resources"], d, config),
18921902
"volume_mounts": flattenCloudRunV2WorkerPoolTemplateContainersVolumeMounts(original["volumeMounts"], d, config),
@@ -1913,6 +1923,10 @@ func flattenCloudRunV2WorkerPoolTemplateContainersArgs(v interface{}, d *schema.
19131923
return v
19141924
}
19151925

1926+
func flattenCloudRunV2WorkerPoolTemplateContainersDependsOn(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1927+
return v
1928+
}
1929+
19161930
func flattenCloudRunV2WorkerPoolTemplateContainersEnv(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
19171931
if v == nil {
19181932
return v
@@ -3381,6 +3395,13 @@ func expandCloudRunV2WorkerPoolTemplateContainers(v interface{}, d tpgresource.T
33813395
transformed["args"] = transformedArgs
33823396
}
33833397

3398+
transformedDependsOn, err := expandCloudRunV2WorkerPoolTemplateContainersDependsOn(original["depends_on"], d, config)
3399+
if err != nil {
3400+
return nil, err
3401+
} else if val := reflect.ValueOf(transformedDependsOn); val.IsValid() && !tpgresource.IsEmptyValue(val) {
3402+
transformed["dependsOn"] = transformedDependsOn
3403+
}
3404+
33843405
transformedEnv, err := expandCloudRunV2WorkerPoolTemplateContainersEnv(original["env"], d, config)
33853406
if err != nil {
33863407
return nil, err
@@ -3444,6 +3465,10 @@ func expandCloudRunV2WorkerPoolTemplateContainersArgs(v interface{}, d tpgresour
34443465
return v, nil
34453466
}
34463467

3468+
func expandCloudRunV2WorkerPoolTemplateContainersDependsOn(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3469+
return v, nil
3470+
}
3471+
34473472
func expandCloudRunV2WorkerPoolTemplateContainersEnv(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
34483473
v = v.(*schema.Set).List()
34493474
if v == nil {

google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fields:
5757
- api_field: 'template.annotations'
5858
- api_field: 'template.containers.args'
5959
- api_field: 'template.containers.command'
60+
- api_field: 'template.containers.dependsOn'
6061
- api_field: 'template.containers.env.name'
6162
- api_field: 'template.containers.env.value'
6263
- api_field: 'template.containers.env.valueSource.secretKeyRef.secret'

google-beta/services/cloudrunv2/resource_cloud_run_v2_worker_pool_generated_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,63 @@ resource "google_cloud_run_v2_worker_pool" "default" {
7272
`, context)
7373
}
7474

75+
func TestAccCloudRunV2WorkerPool_cloudrunv2WorkerPoolBasicDependsOnExample(t *testing.T) {
76+
t.Parallel()
77+
78+
context := map[string]interface{}{
79+
"random_suffix": acctest.RandString(t, 10),
80+
}
81+
82+
acctest.VcrTest(t, resource.TestCase{
83+
PreCheck: func() { acctest.AccTestPreCheck(t) },
84+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
85+
CheckDestroy: testAccCheckCloudRunV2WorkerPoolDestroyProducer(t),
86+
Steps: []resource.TestStep{
87+
{
88+
Config: testAccCloudRunV2WorkerPool_cloudrunv2WorkerPoolBasicDependsOnExample(context),
89+
},
90+
{
91+
ResourceName: "google_cloud_run_v2_worker_pool.default",
92+
ImportState: true,
93+
ImportStateVerify: true,
94+
ImportStateVerifyIgnore: []string{"annotations", "deletion_protection", "labels", "location", "name", "terraform_labels"},
95+
},
96+
},
97+
})
98+
}
99+
100+
func testAccCloudRunV2WorkerPool_cloudrunv2WorkerPoolBasicDependsOnExample(context map[string]interface{}) string {
101+
return acctest.Nprintf(`
102+
resource "google_cloud_run_v2_worker_pool" "default" {
103+
name = "tf-test-cloudrun-worker-pool%{random_suffix}"
104+
location = "us-central1"
105+
deletion_protection = false
106+
launch_stage = "BETA"
107+
108+
template {
109+
containers {
110+
name = "foo-1"
111+
image = "us-docker.pkg.dev/cloudrun/container/worker-pool"
112+
depends_on = ["foo-2"]
113+
}
114+
containers {
115+
name = "foo-2"
116+
image = "us-docker.pkg.dev/cloudrun/container/worker-pool"
117+
startup_probe {
118+
http_get {
119+
path = "/healthz"
120+
port = 8080
121+
}
122+
period_seconds = 5
123+
timeout_seconds = 2
124+
failure_threshold = 3
125+
}
126+
}
127+
}
128+
}
129+
`, context)
130+
}
131+
75132
func TestAccCloudRunV2WorkerPool_cloudrunv2WorkerPoolLimitsExample(t *testing.T) {
76133
t.Parallel()
77134

website/docs/r/cloud_run_v2_worker_pool.html.markdown

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,43 @@ resource "google_cloud_run_v2_worker_pool" "default" {
5252
}
5353
}
5454
```
55+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
56+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=cloudrunv2_worker_pool_basic_depends_on&open_in_editor=main.tf" target="_blank">
57+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
58+
</a>
59+
</div>
60+
## Example Usage - Cloudrunv2 Worker Pool Basic Depends On
61+
62+
63+
```hcl
64+
resource "google_cloud_run_v2_worker_pool" "default" {
65+
name = "cloudrun-worker-pool"
66+
location = "us-central1"
67+
deletion_protection = false
68+
launch_stage = "BETA"
69+
70+
template {
71+
containers {
72+
name = "foo-1"
73+
image = "us-docker.pkg.dev/cloudrun/container/worker-pool"
74+
depends_on = ["foo-2"]
75+
}
76+
containers {
77+
name = "foo-2"
78+
image = "us-docker.pkg.dev/cloudrun/container/worker-pool"
79+
startup_probe {
80+
http_get {
81+
path = "/healthz"
82+
port = 8080
83+
}
84+
period_seconds = 5
85+
timeout_seconds = 2
86+
failure_threshold = 3
87+
}
88+
}
89+
}
90+
}
91+
```
5592
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
5693
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=cloudrunv2_worker_pool_limits&open_in_editor=main.tf" target="_blank">
5794
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
@@ -726,6 +763,10 @@ When the field is set to false, deleting the WorkerPool is allowed.
726763
(Optional)
727764
Arguments to the entrypoint. The docker image's CMD is used if this is not provided. Variable references are not supported in Cloud Run.
728765

766+
* `depends_on` -
767+
(Optional)
768+
Names of the containers that must start before this container.
769+
729770
* `env` -
730771
(Optional)
731772
List of environment variables to set in the container.

0 commit comments

Comments
 (0)