Skip to content

Conversation

@norbjd
Copy link
Contributor

@norbjd norbjd commented Apr 1, 2025

Hello 👋

Just a small fix 🐛

When a function runtime is updated from Terraform:

  1. the runtime field was actually not updated (e.g. when we GET from the API): this is because this case is simply not handled in the existing code
  2. the function is not redeployed. When changing runtime, even if deploy is false, I think most users expect their function to be rebuilt with the new runtime (e.g. when bumping from python310 to python313)

If 2. is controversial, maybe we can just replace:

-	shouldDeploy = shouldDeploy || d.HasChange("runtime")
+	shouldDeploy = shouldDeploy || (d.HasChange("runtime") && deploy)

So, runtime is changed, but function is not redeployed unless explicitly told to do so.

Tests

main.tf:

data "archive_file" "source_zip" {
  type        = "zip"
  source_dir  = "${path.module}/function"
  output_path = "${path.module}/files/function.zip"
}

resource "scaleway_function_namespace" "main" {
  name = "test"
}

resource "scaleway_function" "main" {
  namespace_id = scaleway_function_namespace.main.id
  name         = "test"
  runtime      = "python310"
  deploy        = true
  handler      = "handler.handle"
  privacy      = "public"
  zip_file     = data.archive_file.source_zip.output_path
  zip_hash     = filesha256(data.archive_file.source_zip.output_path)
}

functions/handler.py:

import sys

def handle(event, context):
    return {
        "body": {
            "message": sys.version,
        },
        "statusCode": 200,
    }

Run terraform apply ✔️

Then, change in main.tf:

-  runtime      = "python310"
-  deploy        = true
+  runtime      = "python313"

Running terraform apply redeploys the function ✔️ (we can check the version has changed by calling the function endpoint).

Thanks!

@norbjd norbjd requested a review from a team as a code owner April 1, 2025 15:46
@github-actions github-actions bot added the function Serverless function issues, bugs and feature requests label Apr 1, 2025
@remyleone remyleone enabled auto-merge April 1, 2025 15:48
@remyleone remyleone added this pull request to the merge queue Apr 1, 2025
@norbjd
Copy link
Contributor Author

norbjd commented Apr 1, 2025

Note: maybe there are some tests to add, I don't know 😢

Merged via the queue into scaleway:master with commit d41bded Apr 1, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

function Serverless function issues, bugs and feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants