aboutsummaryrefslogtreecommitdiff
path: root/cmd/ingressd/tf/main.tf
blob: 1206cfb404eb17010f9a47d1e6cb7e1134143a8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
terraform {
  backend "s3" {
    bucket = "within-tf-state"
    key    = "ingressd"
    region = "us-east-1"
  }

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }

    cloudinit = {
      source  = "hashicorp/cloudinit"
      version = "2.3.4"
    }

    tailscale = {
      source  = "tailscale/tailscale"
      version = "0.16.1"
    }

    vultr = {
      source  = "vultr/vultr"
      version = "2.19.0"
    }
  }
}

provider "tailscale" {
  tailnet = "cetacean.org.github"
}

provider "vultr" {
  rate_limit  = 100
  retry_limit = 3
}

data "vultr_os" "rocky" {
  filter {
    name   = "name"
    values = ["Rocky Linux 9 x64"]
  }
}

data "vultr_plan" "ingressd" {
  filter {
    name   = "id"
    values = ["vc2-1c-1gb"]
  }
}

resource "tailscale_tailnet_key" "ingressd" {
  reusable      = true
  ephemeral     = false
  preauthorized = true
  description   = "ingressd key"
  tags          = ["tag:alrest"]
}

data "aws_route53_zone" "cetacean_club" {
  name = "cetacean.club."
}

resource "vultr_instance" "my_instance" {
  plan                = "vc2-1c-2gb"
  region              = "yto"
  os_id               = data.vultr_os.rocky.id
  label               = "ingressd"
  tags                = ["rocky"]
  hostname            = "ingressd"
  enable_ipv6         = true
  disable_public_ipv4 = false
  backups             = "enabled"
  backups_schedule {
    type = "daily"
  }
  ddos_protection  = false
  activation_email = true
  user_data        = <<EOF
#!/bin/sh

curl -fsSL https://tailscale.com/install.sh | sh
tailscale up --authkey ${resource.tailscale_tailnet_key.ingressd.key} --ssh --accept-routes
    EOF
}

resource "aws_route53_record" "A" {
  zone_id = data.aws_route53_zone.cetacean_club.zone_id
  name    = "ingressd.${data.aws_route53_zone.cetacean_club.name}"
  type    = "A"
  ttl     = "300"
  records = [resource.vultr_instance.my_instance.main_ip]
}

resource "aws_route53_record" "AAAA" {
  zone_id = data.aws_route53_zone.cetacean_club.zone_id
  name    = "ingressd.${data.aws_route53_zone.cetacean_club.name}"
  type    = "AAAA"
  ttl     = "300"
  records = [resource.vultr_instance.my_instance.v6_main_ip]
}