variables.tf 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # SPDX-License-Identifier: Apache-2.0
  2. variable "layer" {
  3. type = string
  4. description = "Stack layer, used in the droplet name (for example workload)."
  5. }
  6. variable "region" {
  7. type = string
  8. description = "DigitalOcean region slug."
  9. }
  10. variable "resource_key" {
  11. type = string
  12. default = ""
  13. description = "Key used in the droplet NAME in place of region. Empty means region. Immutable on a live stack: changing it changes the name and may replace the droplet. Never derived from site_name."
  14. validation {
  15. condition = var.resource_key == "" || can(regex("^[a-z][a-z0-9-]{1,23}$", var.resource_key))
  16. error_message = "resource_key must be empty (meaning region) or 2 to 24 characters: a lowercase letter, then lowercase letters, digits or hyphens."
  17. }
  18. }
  19. variable "vpc_id" {
  20. type = string
  21. description = "The VPC the droplet joins. Its private address is the only address Portainer is bound to."
  22. }
  23. variable "tags" {
  24. type = list(string)
  25. description = "Droplet tags, including the baseline tag and the tag the workload firewall attaches to. Set at creation so both firewalls apply from the first second."
  26. validation {
  27. condition = length(var.tags) > 0
  28. error_message = "tags must not be empty: a droplet with no tag has no firewall."
  29. }
  30. }
  31. variable "size" {
  32. type = string
  33. description = "Droplet size slug. The stack reads it from cost.json, the cost gate's single source."
  34. }
  35. variable "ssh_key_fingerprint" {
  36. type = string
  37. description = "Fingerprint of the admin SSH key registered on the account. SSH is reachable only through Twingate."
  38. validation {
  39. condition = length(var.ssh_key_fingerprint) > 0
  40. error_message = "ssh_key_fingerprint must name the admin SSH key; without one the droplet would have no way in."
  41. }
  42. }
  43. variable "admin_ssh_public_key" {
  44. type = string
  45. description = "Public key for the cah-admin user: '<algorithm> <key>' with an optional trailing comment of one word of safe characters. The comment is dropped before the key reaches cloud-init. Key-only access; no password exists."
  46. validation {
  47. condition = can(regex("^(ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp(256|384|521)) [A-Za-z0-9+/]+=*( [A-Za-z0-9@._+:=/-]{1,64})?$", var.admin_ssh_public_key))
  48. error_message = "admin_ssh_public_key must be '<ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp256|384|521> <base64 key>' with at most one trailing comment word of letters, digits and @ . _ + : = / - (no spaces or line breaks)."
  49. }
  50. }
  51. variable "reboot_time" {
  52. type = string
  53. description = "HH:MM (in `timezone`) when unattended-upgrades may reboot this droplet. Choose a time that does not meet the connectors' windows."
  54. validation {
  55. condition = can(regex("^([01][0-9]|2[0-3]):[0-5][0-9]$", var.reboot_time))
  56. error_message = "reboot_time must be HH:MM in 24-hour time, for example 03:30."
  57. }
  58. }
  59. variable "timezone" {
  60. type = string
  61. default = "America/New_York"
  62. description = "IANA time zone name of the machine (UTC or Area/Location). Also the zone reboot_time is read in. Changing it replaces the droplet."
  63. validation {
  64. condition = can(regex("^(UTC|[A-Za-z_]+(/[A-Za-z0-9_+-]+){1,2})$", var.timezone))
  65. error_message = "timezone must be UTC or an IANA name such as America/New_York (Area/Location, letters, digits and _ + - only, no spaces or line breaks)."
  66. }
  67. }
  68. variable "docker_apt_key_fingerprint" {
  69. type = string
  70. default = "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
  71. description = "Primary fingerprint of Docker's apt signing key. The cloud-init refuses a key file that does not hold exactly this one key before it trusts the repository. Changing it changes user_data and replaces the droplet."
  72. validation {
  73. condition = can(regex("^[0-9A-F]{40}$", var.docker_apt_key_fingerprint))
  74. error_message = "docker_apt_key_fingerprint must be a full 40-character fingerprint in uppercase hexadecimal, with no spaces."
  75. }
  76. }
  77. variable "portainer_version" {
  78. type = string
  79. default = "2.45.3@sha256:3609c307943bca8e5c492f69ddd6965df177208b50678a4cff28391c8dd4e96e"
  80. description = "Portainer CE image reference after portainer/portainer-ce:, pinned by exact tag and by digest (2.45.3, an LTS release from Portainer's releases page read 2026-10-31; the multi-arch index digest read from Docker Hub on 2026-11-02). Never latest or a range: Portainer updates only when this is bumped in a reviewed change, which replaces the droplet."
  81. validation {
  82. condition = can(regex("^[0-9]+\\.[0-9]+\\.[0-9]+@sha256:[0-9a-f]{64}$", var.portainer_version))
  83. error_message = "portainer_version must be <exact version>@sha256:<64 hex digits> such as 2.45.3@sha256:..., pinned by tag and by digest, never latest, a range or a variant."
  84. }
  85. }
  86. variable "portainer_port" {
  87. type = number
  88. default = 9443
  89. nullable = false
  90. description = "Host port Portainer's HTTPS UI is published on, bound to the private address only."
  91. validation {
  92. condition = var.portainer_port == floor(var.portainer_port) && var.portainer_port >= 1024 && var.portainer_port <= 65535 && var.portainer_port != 22
  93. error_message = "portainer_port must be a whole port from 1024 to 65535 (never a privileged port, and never SSH's 22)."
  94. }
  95. }
  96. variable "onion_service_enabled" {
  97. type = bool
  98. default = false
  99. nullable = false
  100. description = "Optional, default off (issue #391; lab lesson in the wiki: Lab, publish a web server as a Tor onion service and an I2P site). true adds to the cloud-init a static nginx origin published on 127.0.0.1:8080 only, and a Tor package whose one version 3 onion service forwards to that loopback port. The flag opens no port to the internet and changes no firewall rule, and the service key is made on the host and never appears in the plan or the state. Changing it changes user_data, which replaces the droplet. UNAPPLIED and untested on a real machine."
  101. }
  102. variable "onion_origin_image" {
  103. type = string
  104. default = "nginx:1.30.6-alpine@sha256:0e52bd054126cdc040b1276c0af347aeb02a41b9cfe305d6094767ac30e97949"
  105. description = "Static origin image for the onion service, the official Docker Hub library image pinned by tag and by digest (nginx 1.30.6-alpine, the multi-arch index digest read from Docker Hub on 2026-11-01, the same tag the WordPress-at-scale lab uses). The cloud-init puts the registry and library path in front. Used only when onion_service_enabled is true. Bumped in a reviewed change, which replaces the droplet."
  106. validation {
  107. condition = can(regex("^nginx:[0-9]+\\.[0-9]+\\.[0-9]+-alpine@sha256:[0-9a-f]{64}$", var.onion_origin_image))
  108. error_message = "onion_origin_image must be nginx:<exact version>-alpine@sha256:<64 hex digits>: pinned by tag and by digest, never latest."
  109. }
  110. }