-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloud.tf
91 lines (77 loc) · 1.77 KB
/
cloud.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
resource "hcloud_ssh_key" "ssh_vps_root" {
name = "ssh-vps-root"
public_key = var.ssh_vps_root_key
}
resource "hcloud_server" "vps" {
name = "vps"
image = var.operating_system
server_type = var.server_type
location = var.region
labels = {
"ssh" = "yes",
"http" = "yes"
}
user_data = data.cloudinit_config.cloud_config_vps.rendered
ssh_keys = [
hcloud_ssh_key.ssh_vps_root.id
]
public_net {
ipv4_enabled = true
ipv6_enabled = true
}
}
resource "hcloud_firewall" "allow_ssh" {
name = "allow-ssh"
rule {
direction = "in"
protocol = "tcp"
port = "22"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
apply_to {
label_selector = "ssh=yes"
}
}
resource "hcloud_firewall" "allow_http_https" {
name = "allow-http-https"
rule {
direction = "in"
protocol = "tcp"
port = "80"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction = "in"
protocol = "tcp"
port = "443"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
apply_to {
label_selector = "http=yes"
}
}
# If these firewalls already exist, you can comment the previous section, and uncomment the following section
# data "hcloud_firewall" "block_all_except_ssh" {
# name = "allow-ssh"
# }
# data "hcloud_firewall" "allow_http_https" {
# name = "allow-http-https"
# }
# # Apply the existing firewalls to the server
# resource "hcloud_firewall_attachment" "vps_firewall_ssh" {
# firewall_id = data.hcloud_firewall.block_all_except_ssh.id
# server_ids = [hcloud_server.vps.id]
# }
# resource "hcloud_firewall_attachment" "vps_firewall_http" {
# firewall_id = data.hcloud_firewall.allow_http_https.id
# server_ids = [hcloud_server.vps.id]
# }