From a17d13d881e70773823ce59dd470f2de95f9494f Mon Sep 17 00:00:00 2001 From: norbjd Date: Tue, 1 Apr 2025 17:27:22 +0200 Subject: [PATCH 1/2] fix(functions): update function when runtime has changed and redeploy --- internal/services/function/function.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/services/function/function.go b/internal/services/function/function.go index 6d87c21b73..f9f3321e07 100644 --- a/internal/services/function/function.go +++ b/internal/services/function/function.go @@ -389,6 +389,11 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter updated = true } + if d.HasChange("runtime") { + req.Runtime = function.FunctionRuntime(d.Get("runtime").(string)) + updated = true + } + if updated { _, err = api.UpdateFunction(req, scw.WithContext(ctx)) if err != nil { @@ -401,7 +406,7 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter } zipHasChanged := d.HasChanges("zip_hash", "zip_file") - shouldDeploy := d.Get("deploy").(bool) + deploy := d.Get("deploy").(bool) if zipHasChanged { 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 } } - if d.HasChange("deploy") && shouldDeploy || zipHasChanged && shouldDeploy { + // deploy only in some conditions + shouldDeploy := deploy + shouldDeploy = shouldDeploy || (zipHasChanged && shouldDeploy) + shouldDeploy = shouldDeploy || d.HasChange("runtime") + + if shouldDeploy { _, err := waitForFunction(ctx, api, region, id, d.Timeout(schema.TimeoutUpdate)) if err != nil { return nil From 30b4a8a220ea5a7026c4d905400652459f3133d8 Mon Sep 17 00:00:00 2001 From: norbjd Date: Tue, 1 Apr 2025 17:31:09 +0200 Subject: [PATCH 2/2] shouldDeploy => deploy when zip has changed --- internal/services/function/function.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/function/function.go b/internal/services/function/function.go index f9f3321e07..c58834eb92 100644 --- a/internal/services/function/function.go +++ b/internal/services/function/function.go @@ -417,7 +417,7 @@ func ResourceFunctionUpdate(ctx context.Context, d *schema.ResourceData, m inter // deploy only in some conditions shouldDeploy := deploy - shouldDeploy = shouldDeploy || (zipHasChanged && shouldDeploy) + shouldDeploy = shouldDeploy || (zipHasChanged && deploy) shouldDeploy = shouldDeploy || d.HasChange("runtime") if shouldDeploy {