jdecool/scaleway-runtimepublic Fork
⑂ main
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
docs: fold the probe results in 7b3548aUnverified · on main · Jérémy DECOOL · 10d ago
main.tf · 82 lines · 2.1 KBTerraform Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Deploys the probe function, applied on 2026-11-14 with the scaleway provider v2.92 (see docs/probe-results.md).
# Credentials come from the usual SCW_ACCESS_KEY, SCW_SECRET_KEY and SCW_DEFAULT_PROJECT_ID variables.

terraform {
  required_version = ">= 1.5"

  required_providers {
    scaleway = {
      source  = "scaleway/scaleway"
      version = "~> 2.92"
    }
    archive = {
      source  = "hashicorp/archive"
      version = "~> 2.8"
    }
  }
}

variable "region" {
  type    = string
  default = "fr-par"
}

variable "runtime" {
  type    = string
  default = "php85"
}

provider "scaleway" {
  region = var.region
}

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

resource "scaleway_function_namespace" "probe" {
  name        = "scaleway-runtime-probe"
  description = "Probe measuring the PHP runtime behavior, destroy after use"
}

resource "scaleway_function" "probe" {
  namespace_id = scaleway_function_namespace.probe.id
  name         = "probe-${var.runtime}"
  runtime      = var.runtime
  handler      = "handler.handle"
  privacy      = "public"
  # A single instance makes Warm Process reuse observable between consecutive calls.
  min_scale    = 0
  max_scale    = 1
  memory_limit = 256
  timeout      = 60
  zip_file     = data.archive_file.probe.output_path
  zip_hash     = data.archive_file.probe.output_sha256
  deploy       = true

  # Do plain and secret variables both reach getenv() and $_SERVER?
  environment_variables = {
    PROBE_PLAIN = "plain-value"
  }
  secret_environment_variables = {
    PROBE_SECRET = "secret-value"
  }
}

resource "scaleway_function_cron" "probe" {
  function_id = scaleway_function.probe.id
  name        = "probe-cron"
  schedule    = "*/5 * * * *"
  args        = jsonencode({ probe = "cron", nested = { list = [1, 2] } })

  # Replacing the function (e.g. -var runtime=php84) deletes its CRON triggers server side: recreate them in the same apply.
  lifecycle {
    replace_triggered_by = [scaleway_function.probe.id]
  }
}

output "endpoint" {
  value = "https://${scaleway_function.probe.domain_name}"
}