-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
110 lines (91 loc) · 2.44 KB
/
main.tf
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
104
105
106
107
108
# export DIGITAL_TOKEN = <insert token>
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}
variable "do_token" {}
provider "digitalocean" {
token = var.do_token
}
resource "digitalocean_ssh_key" "web" {
name = "web app SHH key"
public_key = file("${path.module}/files/id_rsa.pub")
}
# Create a new Web Droplet in the nyc2 region
resource "digitalocean_droplet" "web" {
count = 2
image = "ubuntu-20-04-x64"
name = "web-${count.index}"
region = "ams3"
size = "s-1vcpu-1gb"
monitoring = true
#private_networking = false // need to use vpc_uuid instead since private_networking is deprecated
ssh_keys = [digitalocean_ssh_key.web.id]
user_data = file("${path.module}/files/user-data.sh")
}
resource "digitalocean_certificate" "certificate" {
name = "web-certificate-snappy"
type = "lets_encrypt"
domains = ["www.kantorobotics.jp", "kantorobotics.jp", "snappy.kantorobotics.jp"]
}
resource "digitalocean_loadbalancer" "web" {
name = "web-lb"
region = "ams3"
forwarding_rule {
entry_port = 443
entry_protocol = "https"
target_port = 8080
target_protocol = "http"
certificate_id = digitalocean_certificate.certificate.name
}
healthcheck {
port = 8080
protocol = "http"
path = "/"
}
droplet_ids = digitalocean_droplet.web.*.id
}
# Create a new domain
resource "digitalocean_domain" "domain" {
name = "kantorobotics.jp"
}
resource "digitalocean_record" "cname" {
domain = digitalocean_domain.domain.name
type = "CNAME"
name = "www"
value = "relativiteit.github.io."
}
resource "digitalocean_record" "mainSnappy" {
domain = digitalocean_domain.domain.name
type = "A"
name = "snappy"
value = digitalocean_loadbalancer.web.ip
}
resource "digitalocean_record" "github_pages_1" {
domain = digitalocean_domain.domain.name
type = "A"
name = "@"
value = "185.199.108.153"
}
resource "digitalocean_record" "github_pages_2" {
domain = digitalocean_domain.domain.name
type = "A"
name = "@"
value = "185.199.109.153"
}
resource "digitalocean_record" "github_pages_3" {
domain = digitalocean_domain.domain.name
type = "A"
name = "@"
value = "185.199.110.153"
}
resource "digitalocean_record" "github_pages_4" {
domain = digitalocean_domain.domain.name
type = "A"
name = "@"
value = "185.199.111.153"
}