variables.tf 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # SPDX-License-Identifier: Apache-2.0
  2. variable "layer" {
  3. type = string
  4. description = "Stack layer, used in names (for example edge)."
  5. }
  6. variable "region" {
  7. type = string
  8. description = "DigitalOcean region slug. The reserved IP is created in the same region as the droplet."
  9. }
  10. variable "resource_key" {
  11. type = string
  12. default = ""
  13. description = "Key used in resource NAMES in place of region. Empty means region. Immutable on a live stack: changing it changes names and may replace resources, including through user_data. 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 edge VPC (rns-dmz). Never the core VPC."
  22. }
  23. variable "tags" {
  24. type = list(string)
  25. description = "Droplet tags, including the one the Cloud Firewall attaches to. Set at creation."
  26. }
  27. variable "size" {
  28. type = string
  29. description = "Droplet size slug. The stack passes the size it checked against cost.json."
  30. }
  31. variable "public_ports" {
  32. type = list(object({
  33. protocol = string
  34. port_range = string
  35. }))
  36. default = []
  37. description = "Inbound ports open to the whole internet. The host firewall (nftables, default drop) mirrors the Cloud Firewall rule for rule, so the stack passes the same list to both."
  38. validation {
  39. condition = alltrue([
  40. for r in var.public_ports :
  41. contains(["tcp", "udp"], r.protocol) && can(regex("^[1-9][0-9]{0,4}$", r.port_range)) && try(tonumber(r.port_range) <= 65535, false)
  42. ])
  43. error_message = "Each public port needs protocol tcp or udp and a single port_range between 1 and 65535."
  44. }
  45. }
  46. variable "restricted_ports" {
  47. type = list(object({
  48. protocol = string
  49. port_range = string
  50. sources = list(string)
  51. }))
  52. default = []
  53. description = "Inbound ports open only to the listed IPv4 source ranges. An entry with no sources renders no rule at all (closed), in the host firewall as in the Cloud Firewall."
  54. validation {
  55. condition = alltrue([
  56. for r in var.restricted_ports :
  57. contains(["tcp", "udp"], r.protocol) && can(regex("^[1-9][0-9]{0,4}$", r.port_range)) && try(tonumber(r.port_range) <= 65535, false)
  58. ])
  59. error_message = "Each restricted port needs protocol tcp or udp and a single port_range between 1 and 65535."
  60. }
  61. validation {
  62. condition = alltrue([for r in var.restricted_ports : alltrue([for s in r.sources : can(cidrnetmask(s)) && !strcontains(s, ":") && s != "0.0.0.0/0"])])
  63. error_message = "Restricted sources must be IPv4 ranges (a:b notation is IPv6) and never 0.0.0.0/0; a port open to everyone belongs in public_ports."
  64. }
  65. }
  66. variable "timezone" {
  67. type = string
  68. default = "America/New_York"
  69. description = "IANA time zone name of the machine (UTC or Area/Location). Also the zone reboot_time is read in. Eastern by default, the zone the connectors' reboot times and reboot-slots.json are written in."
  70. validation {
  71. condition = can(regex("^(UTC|[A-Za-z_]+(/[A-Za-z0-9_+-]+){1,2})$", var.timezone))
  72. error_message = "timezone must be UTC or an IANA name such as America/New_York."
  73. }
  74. }
  75. variable "service" {
  76. type = string
  77. description = "The one edge service this droplet runs: a key of reboot-slots.json (reticulum, lxmd, i2pd, mosquitto, iperf3). Each service is its own stack and its own droplet; the name, the reboot slot and the Doppler config name follow from it. This module installs no service."
  78. validation {
  79. condition = contains(["reticulum", "lxmd", "i2pd", "mosquitto", "iperf3"], var.service)
  80. error_message = "service must be one of reticulum, lxmd, i2pd, mosquitto, iperf3 (the keys of reboot-slots.json)."
  81. }
  82. }
  83. variable "project_id" {
  84. type = string
  85. description = "Id of the existing DigitalOcean project (the foundation stack's project_id output). The droplet and the reserved IP are attached to it."
  86. }
  87. variable "reboot_time" {
  88. type = string
  89. default = null
  90. description = "HH:MM in `timezone` when unattended-upgrades may reboot this host. null (the default) takes the service's slot from reboot-slots.json (01:00 to 03:00 Eastern, before the connectors' 04:00 and 05:00). A test keeps the slots distinct from each other and from the connectors."
  91. validation {
  92. condition = var.reboot_time == null ? true : can(regex("^([01][0-9]|2[0-3]):[0-5][0-9]$", var.reboot_time))
  93. error_message = "reboot_time must be null or HH:MM in 24-hour time, for example 02:30."
  94. }
  95. }