This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
forked from vitobotta/terraform-hcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
106 lines (87 loc) · 2.76 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
terraform {
required_providers {
# Attention, providers can't be declared in modules
# https://www.terraform.io/docs/modules/providers.html
hcloud = {
source = "hetznercloud/hcloud"
version = "~> 1.27.2"
}
}
}
resource "hcloud_ssh_key" "default" {
for_each = var.ssh_keys
name = each.value.name
public_key = file(each.value.public_key)
}
resource "hcloud_network" "default" {
name = var.private_network_name
ip_range = var.private_ip_range
}
resource "hcloud_network_subnet" "default" {
network_id = hcloud_network.default.id
type = "server"
network_zone = var.private_network_zone
ip_range = var.private_ip_range
}
# resource "hcloud_floating_ip" "default" {
# type = "ipv4"
# home_location = var.hcloud_location
# name = var.floating_ip_name
# }
resource "hcloud_load_balancer" "default" {
name = "load-balancer-servers"
load_balancer_type = var.load_balancer_type
location = var.load_balancer_location
}
resource "hcloud_load_balancer_network" "load_balancer_network" {
load_balancer_id = hcloud_load_balancer.default.id
network_id = hcloud_network.default.id
ip = var.load_balancer_ipv4
}
resource "hcloud_load_balancer_service" "load_balancer_service_6443" {
load_balancer_id = hcloud_load_balancer.default.id
protocol = "tcp"
listen_port = 6443
destination_port = 6443
}
resource "hcloud_load_balancer_service" "load_balancer_service_443" {
load_balancer_id = hcloud_load_balancer.default.id
protocol = "tcp"
listen_port = 443
destination_port = 443
}
resource "hcloud_load_balancer_service" "load_balancer_service_80" {
load_balancer_id = hcloud_load_balancer.default.id
protocol = "tcp"
listen_port = 80
destination_port = 80
}
resource "hcloud_load_balancer_target" "load_balancer_target" {
for_each = hcloud_server.server
type = "server"
load_balancer_id = hcloud_load_balancer.default.id
server_id = each.value.id
use_private_ip = true
depends_on = [
hcloud_server_network.server_network
]
}
resource "hcloud_server" "server" {
for_each = var.servers
name = each.value.name
image = each.value.image
server_type = each.value.server_type
location = each.value.location
backups = each.value.backups
ssh_keys = [for k in hcloud_ssh_key.default : k.name]
user_data = each.value.user_data_file != "" ? file(each.value.user_data_file) : ""
depends_on = [
hcloud_ssh_key.default
]
}
resource "hcloud_server_network" "server_network" {
for_each = var.servers
network_id = hcloud_network.default.id
server_id = hcloud_server.server[each.key].id
ip = each.value.private_ip_address
}