diff --git a/deploy-vm/launch-code-server.sh b/deploy-vm/launch-code-server.sh index e457b04..75e9e7e 100755 --- a/deploy-vm/launch-code-server.sh +++ b/deploy-vm/launch-code-server.sh @@ -39,6 +39,6 @@ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy -sudo echo "ide.terrible.dev \ +sudo echo "${dns_name} \ reverse_proxy 127.0.0.1:8080" > /etc/caddy/Caddyfile sudo systemctl reload caddy \ No newline at end of file diff --git a/main.tf b/main.tf index 283215c..6232cf5 100644 --- a/main.tf +++ b/main.tf @@ -1,14 +1,18 @@ resource "digitalocean_droplet" "web" { - image = "ubuntu-20-04-x64" - name = "web-1" - region = "nyc1" - size = "s-1vcpu-1gb-amd" - ssh_keys = var.ssh_keys - user_data = "${file("deploy-vm/launch-code-server.sh")}" + image = "ubuntu-20-04-x64" + name = "web-1" + region = "nyc1" + size = "s-1vcpu-1gb-amd" + ssh_keys = var.ssh_keys + user_data = templatefile("deploy-vm/launch-code-server.sh", { dns_name = "${var.dns_name}.${cloudflare_zone.main_zone.name}" }) +} + +data "cloudflare_zone" "main_zone" { + zone_id = var.cloudflare_zone } resource "cloudflare_record" "droplet" { - zone_id = var.cloudflare_zone + zone_id = cloudflare_zone.main_zone.id name = "ide" value = digitalocean_droplet.web.ipv4_address type = "A" diff --git a/provider.tf b/provider.tf index c8f5963..69b7ee8 100644 --- a/provider.tf +++ b/provider.tf @@ -1,7 +1,7 @@ terraform { required_providers { digitalocean = { - source = "digitalocean/digitalocean" + source = "digitalocean/digitalocean" version = "~> 2.0" } cloudflare = { @@ -19,6 +19,6 @@ provider "digitalocean" { } provider "cloudflare" { - email = var.cloudflare_email + email = var.cloudflare_email api_token = var.cloudflare_api_token } \ No newline at end of file diff --git a/variables.tf b/variables.tf index 7fd6a5e..215110b 100644 --- a/variables.tf +++ b/variables.tf @@ -1,17 +1,22 @@ variable "do_token" { - type = string + type = string } variable "cloudflare_email" { - type = string + type = string } variable "cloudflare_api_token" { - type = string + type = string } variable "cloudflare_zone" { - type = string + type = string } variable "ssh_keys" { - type = list(string) + type = list(string) +} + +variable "dns_name" { + type = string + default = "ide" } \ No newline at end of file