forked from kubermatic/terraform-provider-kubermatic
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.tf
228 lines (203 loc) · 6.46 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
terraform {
required_providers {
metakube = {
source = "syseleven/metakube"
}
openstack = {
source = "terraform-provider-openstack/openstack"
}
}
}
// You can download and source "OpenStack RC File v3" for your account at https://cloud.syseleven.de or configure it here.
// provider "openstack" {
// auth_url = "https://keystone.cloud.syseleven.net:5000/v3"
//
// user_name = var.username
//
// password = var.password
//
// tenant_name = var.tenant
//
// domain_name = "Default"
// }
# Create openstack security for cluster internal network.
resource "openstack_networking_secgroup_v2" "cluster-net" {
name = var.server_group_name
}
# Add rules to internal networks security group.
resource "openstack_networking_secgroup_rule_v2" "allow_ipv4_within_group" {
direction = "ingress"
ethertype = "IPv4"
remote_group_id = openstack_networking_secgroup_v2.cluster-net.id
security_group_id = openstack_networking_secgroup_v2.cluster-net.id
}
resource "openstack_networking_secgroup_rule_v2" "allow_ipv6_within_group" {
direction = "ingress"
ethertype = "IPv6"
remote_group_id = openstack_networking_secgroup_v2.cluster-net.id
security_group_id = openstack_networking_secgroup_v2.cluster-net.id
}
resource "openstack_networking_secgroup_rule_v2" "allow_ssh" {
direction = "ingress"
ethertype = "IPv4"
port_range_min = 22
port_range_max = 22
protocol = "tcp"
security_group_id = openstack_networking_secgroup_v2.cluster-net.id
}
resource "openstack_networking_secgroup_rule_v2" "allow_icmp" {
direction = "ingress"
ethertype = "IPv4"
protocol = "icmp"
security_group_id = openstack_networking_secgroup_v2.cluster-net.id
}
resource "openstack_networking_secgroup_rule_v2" "allow_icmp6" {
direction = "ingress"
ethertype = "IPv6"
protocol = "ipv6-icmp"
security_group_id = openstack_networking_secgroup_v2.cluster-net.id
}
resource "openstack_networking_secgroup_rule_v2" "allow_higher_ports" {
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
security_group_id = openstack_networking_secgroup_v2.cluster-net.id
port_range_min = 30000
port_range_max = 32767
remote_ip_prefix = "192.168.1.0/24"
}
# Create cluster internal network.
resource "openstack_networking_network_v2" "network_1" {
name = var.cluster_network_name
admin_state_up = true
}
resource "openstack_networking_subnet_v2" "subnet_1" {
name = var.subnet_name
network_id = openstack_networking_network_v2.network_1.id
cidr = "192.168.1.0/24"
ip_version = 4
enable_dhcp = true
allocation_pool {
start = "192.168.1.2"
end = "192.168.1.254"
}
# Internal IPs of DNS Servers in the cloud.
dns_nameservers = [
"37.123.105.116",
"37.123.105.117"]
}
resource "openstack_compute_servergroup_v2" "anti-affinity" {
name = "test-anti-affinity"
policies = ["anti-affinity"]
}
# Set up a router to allow access through public internet.
data "openstack_networking_network_v2" "external" {
name = var.floating_ip_pool
}
resource "openstack_networking_router_v2" "router_1" {
name = var.router_name
admin_state_up = true
external_network_id = data.openstack_networking_network_v2.external.id
}
resource "openstack_networking_router_interface_v2" "router_interface_1" {
router_id = openstack_networking_router_v2.router_1.id
subnet_id = openstack_networking_subnet_v2.subnet_1.id
}
# The latest Ubuntu 18.04 image available.
data "openstack_images_image_v2" "image" {
most_recent = true
visibility = "public"
properties = {
os_distro = "ubuntu"
os_version = "18.04"
}
}
# Read local sshkey's public part and publish it to MetaKube.
data "local_file" "public_sshkey" {
filename = pathexpand(var.public_sshkey_file)
}
resource "metakube_sshkey" "local" {
project_id = var.project_id
name = "local SSH key"
public_key = data.local_file.public_sshkey.content
}
data "metakube_k8s_version" "cluster" {
major = "1"
minor = "21"
}
resource "metakube_cluster" "cluster" {
name = var.cluster_name
dc_name = var.dc_name
project_id = var.project_id
sshkeys = [metakube_sshkey.local.id]
# add labels
labels = {
"test-key" = "test-value"
}
spec {
enable_ssh_agent = true
version = data.metakube_k8s_version.cluster.version
cloud {
openstack {
user_credentials {
project_id = var.openstack_project_id
project_name = var.openstack_project_name
username = var.username
password = var.password
}
floating_ip_pool = data.openstack_networking_network_v2.external.name
security_group = openstack_networking_secgroup_v2.cluster-net.name
network = openstack_networking_network_v2.network_1.name
subnet_id = openstack_networking_subnet_v2.subnet_1.id
subnet_cidr = openstack_networking_secgroup_rule_v2.allow_higher_ports.remote_ip_prefix
server_group_id = openstack_compute_servergroup_v2.anti-affinity.id
}
}
# enable audit logging
audit_logging = true
pod_node_selector = true
pod_security_policy = true
services_cidr = "10.240.16.0/20"
pods_cidr = "172.25.0.0/16"
}
}
# create admin.conf file
resource "local_file" "kubeconfig" {
content = metakube_cluster.cluster.kube_config
filename = "${path.module}/admin.conf"
}
resource "metakube_node_deployment" "acctest_nd" {
cluster_id = metakube_cluster.cluster.id
name = null # auto generate
spec {
min_replicas = var.node_min_replicas
max_replicas = var.node_max_replicas
dynamic_config = true
template {
labels = {
key = "value"
}
cloud {
openstack {
flavor = var.node_flavor
disk_size = var.node_disk_size
image = var.node_image != null ? var.node_image : data.openstack_images_image_v2.image.name
use_floating_ip = var.use_floating_ip
instance_ready_check_period = "5s"
instance_ready_check_timeout = "100s"
tags = {
foo = "bar"
}
}
}
operating_system {
ubuntu {
dist_upgrade_on_boot = true
}
}
versions {
kubelet = data.metakube_k8s_version.cluster.version
}
}
}
}