main.tf 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # SPDX-License-Identifier: Apache-2.0
  2. # One hardened Docker host (stage 3, design docs/superpowers/specs/2026-10-11-stage-3-workloads-design.md
  3. # section 5.3): a droplet in the VPC running Docker Engine and Portainer CE,
  4. # set up by cloud-init. There is no Twingate connector in it; the stack gives the
  5. # host its firewall and its Twingate resources. UNAPPLIED: only stacks/30-workloads
  6. # calls this module, behind a switch that defaults to off.
  7. locals {
  8. # Names use resource_key when it is set and region otherwise.
  9. name_key = var.resource_key != "" ? var.resource_key : var.region
  10. # What the cloud-init gets for the admin key: "<algorithm> <key>" only. A
  11. # trailing comment is accepted by the variable's validation and dropped here.
  12. admin_key_parts = split(" ", var.admin_ssh_public_key)
  13. admin_key = "${local.admin_key_parts[0]} ${local.admin_key_parts[1]}"
  14. }
  15. resource "digitalocean_droplet" "workload" {
  16. name = "${var.layer}-${local.name_key}-docker"
  17. region = var.region
  18. size = var.size
  19. image = "ubuntu-24-04-x64"
  20. vpc_uuid = var.vpc_id
  21. tags = var.tags
  22. ssh_keys = [var.ssh_key_fingerprint]
  23. ipv6 = false
  24. backups = false
  25. monitoring = true
  26. user_data = templatefile("${path.module}/cloud-init.yaml.tftpl", {
  27. timezone = var.timezone
  28. reboot_time = var.reboot_time
  29. admin_ssh_public_key = local.admin_key
  30. docker_key_fingerprint = var.docker_apt_key_fingerprint
  31. portainer_version = var.portainer_version
  32. portainer_port = var.portainer_port
  33. onion_service_enabled = var.onion_service_enabled
  34. onion_origin_image = var.onion_origin_image
  35. })
  36. }