Skip to content

Commit d41bded

Browse files
authored
fix(functions): update function when runtime has changed and redeploy (#3011)
* fix(functions): update function when runtime has changed and redeploy * shouldDeploy => deploy when zip has changed
1 parent 8622a34 commit d41bded

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

internal/services/function/function.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter
389389
updated = true
390390
}
391391

392+
if d.HasChange("runtime") {
393+
req.Runtime = function.FunctionRuntime(d.Get("runtime").(string))
394+
updated = true
395+
}
396+
392397
if updated {
393398
_, err = api.UpdateFunction(req, scw.WithContext(ctx))
394399
if err != nil {
@@ -401,7 +406,7 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter
401406
}
402407

403408
zipHasChanged := d.HasChanges("zip_hash", "zip_file")
404-
shouldDeploy := d.Get("deploy").(bool)
409+
deploy := d.Get("deploy").(bool)
405410

406411
if zipHasChanged {
407412
err = functionUpload(ctx, m, api, region, f.ID, d.Get("zip_file").(string))
@@ -410,7 +415,12 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter
410415
}
411416
}
412417

413-
if d.HasChange("deploy") && shouldDeploy || zipHasChanged && shouldDeploy {
418+
// deploy only in some conditions
419+
shouldDeploy := deploy
420+
shouldDeploy = shouldDeploy || (zipHasChanged && deploy)
421+
shouldDeploy = shouldDeploy || d.HasChange("runtime")
422+
423+
if shouldDeploy {
414424
_, err := waitForFunction(ctx, api, region, id, d.Timeout(schema.TimeoutUpdate))
415425
if err != nil {
416426
return nil

0 commit comments

Comments
 (0)