Skip to content

Commit 8bc672d

Browse files
Feat: Add min_instances to cloudfunctions functions (#5513) (#10712)
Signed-off-by: Modular Magician <[email protected]>
1 parent 450efe2 commit 8bc672d

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

.changelog/5513.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudfunctions: added support for `min_instances` to `google_cloudfunctions_function`
3+
```

google/resource_cloudfunctions_function.go

+19
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ func resourceCloudFunctionsFunction() *schema.Resource {
293293
Description: `The limit on the maximum number of function instances that may coexist at a given time.`,
294294
},
295295

296+
"min_instances": {
297+
Type: schema.TypeInt,
298+
Optional: true,
299+
ValidateFunc: validation.IntAtLeast(0),
300+
Description: `The limit on the minimum number of function instances that may coexist at a given time.`,
301+
},
302+
296303
"project": {
297304
Type: schema.TypeString,
298305
Optional: true,
@@ -409,6 +416,10 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
409416
function.MaxInstances = int64(v.(int))
410417
}
411418

419+
if v, ok := d.GetOk("min_instances"); ok {
420+
function.MinInstances = int64(v.(int))
421+
}
422+
412423
log.Printf("[DEBUG] Creating cloud function: %s", function.Name)
413424

414425
// We retry the whole create-and-wait because Cloud Functions
@@ -527,6 +538,9 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error
527538
if err := d.Set("max_instances", function.MaxInstances); err != nil {
528539
return fmt.Errorf("Error setting max_instances: %s", err)
529540
}
541+
if err := d.Set("min_instances", function.MinInstances); err != nil {
542+
return fmt.Errorf("Error setting min_instances: %s", err)
543+
}
530544
if err := d.Set("region", cloudFuncId.Region); err != nil {
531545
return fmt.Errorf("Error setting region: %s", err)
532546
}
@@ -641,6 +655,11 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
641655
updateMaskArr = append(updateMaskArr, "maxInstances")
642656
}
643657

658+
if d.HasChange("min_instances") {
659+
function.MinInstances = int64(d.Get("min_instances").(int))
660+
updateMaskArr = append(updateMaskArr, "minInstances")
661+
}
662+
644663
if len(updateMaskArr) > 0 {
645664
log.Printf("[DEBUG] Send Patch CloudFunction Configuration request: %#v", function)
646665
updateMask := strings.Join(updateMaskArr, ",")

google/resource_cloudfunctions_function_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func TestAccCloudFunctionsFunction_basic(t *testing.T) {
145145
"available_memory_mb", "128"),
146146
resource.TestCheckResourceAttr(funcResourceName,
147147
"max_instances", "10"),
148+
resource.TestCheckResourceAttr(funcResourceName,
149+
"min_instances", "3"),
148150
resource.TestCheckResourceAttr(funcResourceName,
149151
"ingress_settings", "ALLOW_INTERNAL_ONLY"),
150152
testAccCloudFunctionsFunctionSource(fmt.Sprintf("gs://%s/index.zip", bucketName), &function),
@@ -215,6 +217,8 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
215217
"timeout", "91"),
216218
resource.TestCheckResourceAttr(funcResourceName,
217219
"max_instances", "15"),
220+
resource.TestCheckResourceAttr(funcResourceName,
221+
"min_instances", "5"),
218222
resource.TestCheckResourceAttr(funcResourceName,
219223
"ingress_settings", "ALLOW_ALL"),
220224
testAccCloudFunctionsFunctionHasLabel("my-label", "my-updated-label-value", &function),
@@ -623,6 +627,7 @@ resource "google_cloudfunctions_function" "function" {
623627
TEST_ENV_VARIABLE = "test-build-env-variable-value"
624628
}
625629
max_instances = 10
630+
min_instances = 3
626631
}
627632
`, bucketName, zipFilePath, functionName)
628633
}
@@ -664,6 +669,7 @@ resource "google_cloudfunctions_function" "function" {
664669
NEW_ENV_VARIABLE = "new-build-env-variable-value"
665670
}
666671
max_instances = 15
672+
min_instances = 5
667673
}
668674
`, bucketName, zipFilePath, functionName)
669675
}
@@ -903,6 +909,7 @@ resource "google_cloudfunctions_function" "function" {
903909
TEST_ENV_VARIABLE = "test-env-variable-value"
904910
}
905911
max_instances = 10
912+
min_instances = 3
906913
vpc_connector = google_vpc_access_connector.%s.self_link
907914
vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY"
908915

website/docs/r/cloudfunctions_function.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ Eg. `"nodejs10"`, `"nodejs12"`, `"nodejs14"`, `"python37"`, `"python38"`, `"pyth
150150

151151
* `max_instances` - (Optional) The limit on the maximum number of function instances that may coexist at a given time.
152152

153+
* `min_instances` - (Optional) The limit on the minimum number of function instances that may coexist at a given time.
154+
153155
<a name="nested_event_trigger"></a>The `event_trigger` block supports:
154156

155157
* `event_type` - (Required) The type of event to observe. For example: `"google.storage.object.finalize"`.

0 commit comments

Comments
 (0)