Skip to content

Instantly share code, notes, and snippets.

@charles-l
Last active April 30, 2023 20:44
Show Gist options
  • Save charles-l/a907c9ead51ce35fedfccf2f5521e894 to your computer and use it in GitHub Desktop.
Save charles-l/a907c9ead51ce35fedfccf2f5521e894 to your computer and use it in GitHub Desktop.
terraform notes: provision a server with tailscale automatically
terraform {
required_providers {
tailscale = {
source = "tailscale/tailscale"
version = "0.13.7"
}
}
}
provider "tailscale" {
api_key = var.TAILSCALE_API_KEY
tailnet = "user@email.com" # username
}
variable "TAILSCALE_API_KEY" {}
resource "tailscale_tailnet_key" "setup_key" {
reusable = true
ephemeral = false
preauthorized = false
expiry = 600
}
resource "vultr_instance" "web" {
plan = "vc2-1c-0.5gb"
region = "ewr"
os_id = 477
enable_ipv6 = true
user_data = <<-EOT
#cloud-config
apt:
sources:
tailscale.list:
source: deb https://pkgs.tailscale.com/stable/ubuntu focal main
keyid: 2596A99EAAB33821893C0A79458CA832957F5868
package_update: true
package_upgrade: true
packages:
- tailscale
runcmd:
- [tailscale, up, -authkey, ${tailscale_tailnet_key.setup_key.key}]
- ufw allow in on tailscale0
EOT
hostname = "webserver"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment