Last active
September 8, 2024 22:40
-
-
Save rossedman/87abb57aafb53030e881b410ea66ba4b to your computer and use it in GitHub Desktop.
Scale homelab into cloud with Tailscale, Terraform and cloud-init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
digitalocean = { | |
source = "digitalocean/digitalocean" | |
} | |
} | |
} | |
provider "digitalocean" { | |
} | |
variable "tailscale_key" { | |
type = "string" | |
} | |
resource "digitalocean_vpc" "homelab" { | |
name = "homelab" | |
region = "nyc3" | |
ip_range = "10.10.10.0/24" | |
} | |
resource "digitalocean_ssh_key" "default" { | |
name = "Labscale - Terraform" | |
public_key = file("~/.ssh/id_rsa.pub") | |
} | |
resource "digitalocean_droplet" "server" { | |
count = 3 | |
name = "server-${count.index}" | |
size = "s-1vcpu-1gb" | |
image = "ubuntu-20-04-x64" | |
region = digitalocean_vpc.homelab.region | |
vpc_uuid = digitalocean_vpc.homelab.id | |
ssh_keys = [digitalocean_ssh_key.default.fingerprint] | |
user_data = templatefile("${path.module}/userdata.tpl", { | |
tailscale_key = var.tailscale_key | |
}) | |
} | |
resource "digitalocean_project" "labscale" { | |
name = "labscale" | |
description = "A project for scaling homelab with tailscale" | |
resources = digitalocean_droplet.server.*.urn | |
} | |
output "public_ip" { | |
value = digitalocean_droplet.server.*.ipv4_address | |
} | |
output "private_ip" { | |
value = digitalocean_droplet.server.*.ipv4_address_private | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
# this variant installs docker as well as tailscale | |
# using these together you could create a really simple | |
# container homelab for quick learning and low cost | |
--- | |
ssh_pwauth: false | |
apt: | |
sources: | |
tailscale.list: | |
source: deb https://pkgs.tailscale.com/stable/ubuntu focal main | |
keyid: 2596A99EAAB33821893C0A79458CA832957F5868 | |
docker.list: | |
source: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable | |
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 | |
packages: | |
- docker-ce | |
- docker-ce-cli | |
- tailscale | |
runcmd: | |
- tailscale up -authkey ${tailscale_key} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
--- | |
apt: | |
sources: | |
tailscale.list: | |
source: deb https://pkgs.tailscale.com/stable/ubuntu focal main | |
keyid: 2596A99EAAB33821893C0A79458CA832957F5868 | |
packages: | |
- tailscale | |
runcmd: | |
- [tailscale, up, -authkey, ${tailscale_key}] |
@rossedman Thank you for sharing these configs especially with TailScale setup, but this part:
runcmd:
- [tailscale, up, -authkey, ${tailscale_key}]
unfortunately does not work in my case.
I have posted on Ask Ubuntu two questions(one, two) about this. Maybe you know the solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this: