-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.tf
102 lines (91 loc) · 2.38 KB
/
server.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
#############################
### Create Nodes
#############################
resource "aws_launch_template" "k3s_server" {
name_prefix = "${local.name}-server"
image_id = local.server_image_id
user_data = data.cloudinit_config.k3s_server.rendered
iam_instance_profile {
name = aws_iam_instance_profile.ec2_instance_profile.name
}
block_device_mappings {
device_name = "/dev/sda1"
ebs {
encrypted = true
volume_type = local.server_volume_type
volume_size = "50"
}
}
network_interfaces {
associate_public_ip_address = true
delete_on_termination = true
security_groups = concat([aws_security_group.ingress.id, aws_security_group.self.id], var.extra_server_security_groups)
}
tags = {
Name = "${local.name}-server"
}
tag_specifications {
resource_type = "instance"
tags = {
Name = "${local.name}-server"
}
}
}
resource "aws_autoscaling_group" "k3s_server" {
name_prefix = "${local.name}-server"
max_size = 1
min_size = 0
vpc_zone_identifier = [local.public_subnets[0]]
instance_refresh {
strategy = "Rolling"
preferences {
min_healthy_percentage = 50
}
}
mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = var.use_spot_instance ? 0 : 1
on_demand_percentage_above_base_capacity = var.use_spot_instance ? 0 : 100
}
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.k3s_server.id
version = aws_launch_template.k3s_server.latest_version
}
dynamic "override" {
for_each = var.server_instance_types
content {
instance_type = override.value
}
}
}
}
}
resource "aws_ssm_parameter" "k3sCerts" {
for_each = toset(["client-ca-key", "client-ca-crt", "server-ca-key", "server-ca-crt", "request-header-ca-key", "request-header-ca-crt"])
name = "/k3s/${each.key}"
type = "String"
value = " "
lifecycle {
ignore_changes = [
value,
]
}
}
resource "aws_ssm_parameter" "k3sConfig" {
count = 2
name = "/k3s/kubeconfig/${count.index + 1}"
type = "String"
value = " "
lifecycle {
ignore_changes = [
value,
]
}
}
resource "aws_eip" "this" {
count = 1
tags = {
"Name" = "fixed IP for k3s simple"
}
}