Skip to content

Commit 513a5fb

Browse files
Add max instance count field to Cloud Run Service (#14724) (#10558)
[upstream:22a40032828fb18bbb472f686e94fed8b93b254d] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 40f3296 commit 513a5fb

8 files changed

+147
-35
lines changed

.changelog/14724.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 `max_instance_count` field to `google_cloud_run_v2_service` resource.
3+
```

google-beta/services/cloudrunv2/iam_cloud_run_v2_service_generated_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ resource "google_cloud_run_v2_service" "default" {
132132
location = "us-central1"
133133
deletion_protection = false
134134
ingress = "INGRESS_TRAFFIC_ALL"
135+
136+
scaling {
137+
max_instance_count = 100
138+
}
135139
136140
template {
137141
containers {
@@ -157,6 +161,10 @@ resource "google_cloud_run_v2_service" "default" {
157161
location = "us-central1"
158162
deletion_protection = false
159163
ingress = "INGRESS_TRAFFIC_ALL"
164+
165+
scaling {
166+
max_instance_count = 100
167+
}
160168
161169
template {
162170
containers {
@@ -197,6 +205,10 @@ resource "google_cloud_run_v2_service" "default" {
197205
location = "us-central1"
198206
deletion_protection = false
199207
ingress = "INGRESS_TRAFFIC_ALL"
208+
209+
scaling {
210+
max_instance_count = 100
211+
}
200212
201213
template {
202214
containers {
@@ -224,6 +236,10 @@ resource "google_cloud_run_v2_service" "default" {
224236
location = "us-central1"
225237
deletion_protection = false
226238
ingress = "INGRESS_TRAFFIC_ALL"
239+
240+
scaling {
241+
max_instance_count = 100
242+
}
227243
228244
template {
229245
containers {
@@ -249,6 +265,10 @@ resource "google_cloud_run_v2_service" "default" {
249265
location = "us-central1"
250266
deletion_protection = false
251267
ingress = "INGRESS_TRAFFIC_ALL"
268+
269+
scaling {
270+
max_instance_count = 100
271+
}
252272
253273
template {
254274
containers {

google-beta/services/cloudrunv2/resource_cloud_run_v2_service.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,11 @@ For example, if ALPHA is provided as input, but only BETA and GA-level features
976976
Optional: true,
977977
Description: `Total instance count for the service in manual scaling mode. This number of instances is divided among all revisions with specified traffic based on the percent of traffic they are receiving.`,
978978
},
979+
"max_instance_count": {
980+
Type: schema.TypeInt,
981+
Optional: true,
982+
Description: `Combined maximum number of instances for all revisions receiving traffic.`,
983+
},
979984
"min_instance_count": {
980985
Type: schema.TypeInt,
981986
Optional: true,
@@ -2016,6 +2021,8 @@ func flattenCloudRunV2ServiceScaling(v interface{}, d *schema.ResourceData, conf
20162021
transformed := make(map[string]interface{})
20172022
transformed["min_instance_count"] =
20182023
flattenCloudRunV2ServiceScalingMinInstanceCount(original["minInstanceCount"], d, config)
2024+
transformed["max_instance_count"] =
2025+
flattenCloudRunV2ServiceScalingMaxInstanceCount(original["maxInstanceCount"], d, config)
20192026
transformed["scaling_mode"] =
20202027
flattenCloudRunV2ServiceScalingScalingMode(original["scalingMode"], d, config)
20212028
transformed["manual_instance_count"] =
@@ -2039,6 +2046,23 @@ func flattenCloudRunV2ServiceScalingMinInstanceCount(v interface{}, d *schema.Re
20392046
return v // let terraform core handle it otherwise
20402047
}
20412048

2049+
func flattenCloudRunV2ServiceScalingMaxInstanceCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
2050+
// Handles the string fixed64 format
2051+
if strVal, ok := v.(string); ok {
2052+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
2053+
return intVal
2054+
}
2055+
}
2056+
2057+
// number values are represented as float64
2058+
if floatVal, ok := v.(float64); ok {
2059+
intVal := int(floatVal)
2060+
return intVal
2061+
}
2062+
2063+
return v // let terraform core handle it otherwise
2064+
}
2065+
20422066
func flattenCloudRunV2ServiceScalingScalingMode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
20432067
return v
20442068
}
@@ -3616,6 +3640,13 @@ func expandCloudRunV2ServiceScaling(v interface{}, d tpgresource.TerraformResour
36163640
transformed["minInstanceCount"] = transformedMinInstanceCount
36173641
}
36183642

3643+
transformedMaxInstanceCount, err := expandCloudRunV2ServiceScalingMaxInstanceCount(original["max_instance_count"], d, config)
3644+
if err != nil {
3645+
return nil, err
3646+
} else if val := reflect.ValueOf(transformedMaxInstanceCount); val.IsValid() && !tpgresource.IsEmptyValue(val) {
3647+
transformed["maxInstanceCount"] = transformedMaxInstanceCount
3648+
}
3649+
36193650
transformedScalingMode, err := expandCloudRunV2ServiceScalingScalingMode(original["scaling_mode"], d, config)
36203651
if err != nil {
36213652
return nil, err
@@ -3637,6 +3668,10 @@ func expandCloudRunV2ServiceScalingMinInstanceCount(v interface{}, d tpgresource
36373668
return v, nil
36383669
}
36393670

3671+
func expandCloudRunV2ServiceScalingMaxInstanceCount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3672+
return v, nil
3673+
}
3674+
36403675
func expandCloudRunV2ServiceScalingScalingMode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
36413676
return v, nil
36423677
}

google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fields:
5858
- field: 'observed_generation'
5959
- field: 'reconciling'
6060
- field: 'scaling.manual_instance_count'
61+
- field: 'scaling.max_instance_count'
6162
- field: 'scaling.min_instance_count'
6263
- field: 'scaling.scaling_mode'
6364
- field: 'template.annotations'

google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ resource "google_cloud_run_v2_service" "default" {
6262
location = "us-central1"
6363
deletion_protection = false
6464
ingress = "INGRESS_TRAFFIC_ALL"
65+
66+
scaling {
67+
max_instance_count = 100
68+
}
6569
6670
template {
6771
containers {
@@ -154,11 +158,11 @@ resource "google_cloud_run_v2_service" "default" {
154158
deletion_protection = false
155159
ingress = "INGRESS_TRAFFIC_ALL"
156160
157-
template {
158-
scaling {
159-
max_instance_count = 2
160-
}
161-
161+
scaling {
162+
max_instance_count = 2
163+
}
164+
165+
template {
162166
volumes {
163167
name = "cloudsql"
164168
cloud_sql_instance {
@@ -378,6 +382,10 @@ resource "google_cloud_run_v2_service" "default" {
378382
deletion_protection = false
379383
ingress = "INGRESS_TRAFFIC_ALL"
380384
385+
scaling {
386+
max_instance_count = 1
387+
}
388+
381389
template {
382390
containers {
383391
image = "us-docker.pkg.dev/cloudrun/container/hello"
@@ -394,9 +402,6 @@ resource "google_cloud_run_v2_service" "default" {
394402
accelerator = "nvidia-l4"
395403
}
396404
gpu_zonal_redundancy_disabled = true
397-
scaling {
398-
max_instance_count = 1
399-
}
400405
}
401406
}
402407
`, context)

google-beta/services/cloudrunv2/resource_cloud_run_v2_service_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ resource "google_cloud_run_v2_service" "default" {
7878
}
7979
client = "client-1"
8080
client_version = "client-version-1"
81+
scaling {
82+
min_instance_count = 1
83+
max_instance_count = 3
84+
}
8185
template {
8286
labels = {
8387
label-1 = "value-1"
8488
}
8589
timeout = "300s"
8690
service_account = google_service_account.service_account.email
8791
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
88-
scaling {
89-
max_instance_count = 3
90-
min_instance_count = 1
91-
}
9292
annotations = {
9393
generated-by = "magic-modules"
9494
}
@@ -146,18 +146,17 @@ resource "google_cloud_run_v2_service" "default" {
146146
}
147147
client = "client-update"
148148
client_version = "client-version-update"
149-
149+
scaling {
150+
min_instance_count = 1
151+
max_instance_count = 2
152+
}
150153
template {
151154
labels = {
152155
label-1 = "value-update"
153156
}
154157
timeout = "500s"
155158
service_account = google_service_account.service_account.email
156159
execution_environment = "EXECUTION_ENVIRONMENT_GEN1"
157-
scaling {
158-
max_instance_count = 2
159-
min_instance_count = 1
160-
}
161160
annotations = {
162161
generated-by = "magic-modules"
163162
}
@@ -268,17 +267,17 @@ resource "google_cloud_run_v2_service" "default" {
268267
}
269268
client = "client-1"
270269
client_version = "client-version-1"
270+
scaling {
271+
min_instance_count = 1
272+
max_instance_count = 3
273+
}
271274
template {
272275
labels = {
273276
label-1 = "value-1"
274277
}
275278
timeout = "300s"
276279
service_account = google_service_account.service_account.email
277280
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
278-
scaling {
279-
max_instance_count = 3
280-
min_instance_count = 1
281-
}
282281
annotations = {
283282
generated-by = "magic-modules"
284283
}
@@ -1332,6 +1331,9 @@ resource "google_cloud_run_v2_service" "default" {
13321331
}
13331332
client = "client-1"
13341333
client_version = "client-version-1"
1334+
scaling {
1335+
max_instance_count = 1
1336+
}
13351337
template {
13361338
containers {
13371339
image = "us-docker.pkg.dev/cloudrun/container/hello"
@@ -1343,9 +1345,6 @@ resource "google_cloud_run_v2_service" "default" {
13431345
startup_cpu_boost = true
13441346
}
13451347
}
1346-
scaling {
1347-
max_instance_count = 1
1348-
}
13491348
}
13501349
}
13511350
`, context)
@@ -1367,6 +1366,9 @@ resource "google_cloud_run_v2_service" "default" {
13671366
}
13681367
client = "client-1"
13691368
client_version = "client-version-1"
1369+
scaling {
1370+
max_instance_count = 1
1371+
}
13701372
template {
13711373
containers {
13721374
image = "us-docker.pkg.dev/cloudrun/container/hello"
@@ -1383,9 +1385,6 @@ resource "google_cloud_run_v2_service" "default" {
13831385
accelerator = "nvidia-l4"
13841386
}
13851387
gpu_zonal_redundancy_disabled = true
1386-
scaling {
1387-
max_instance_count = 1
1388-
}
13891388
}
13901389
}
13911390
`, context)

0 commit comments

Comments
 (0)