-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathlocals.tf
73 lines (68 loc) · 3.94 KB
/
locals.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
locals {
USER_ID = var.USER_ID == "" ? "defaultUser" : var.USER_ID
ENV_ID = var.ENV_ID == "" ? "defaultId" : var.ENV_ID
prefix_id = "${local.USER_ID}_${local.ENV_ID}"
prefix = "${local.prefix_id}_${var.prefix}"
item_id_lock = "CMDB_lock_${local.USER_ID}_${local.ENV_ID}_${var.app_name}_${var.prefix}"
item_id_data = "CMDB_data_${local.USER_ID}_${local.ENV_ID}_${var.app_name}_${var.prefix}"
subnets_az = distinct(split(",", (var.subnets_az)))
subnets = [for item in local.subnets_az : split("=", item)[0]]
az = [for item in local.subnets_az : split("=", item)[1]]
tags_app = {
"Name" = "${local.prefix}-${var.app_name}"
"app_name" = var.app_name
}
tags_all = merge(var.tags_common, local.tags_app)
tags_k8_master = {
"k8_node_type" = "master"
"Name" = "${local.prefix}-${var.app_name}-master"
}
tags_all_k8_master = var.node_type == "spot" ? merge(local.tags_all, local.tags_k8_master) : {}
tags_k8_worker = {
"k8_node_type" = "worker"
"Name" = "${local.prefix}-${var.app_name}-worker"
}
tags_all_k8_worker = merge(local.tags_all, local.tags_k8_worker)
worker_join = "${var.s3_k8s_config}/config/${local.USER_ID}/${local.ENV_ID}/${var.cluster_name}-${local.target_time_stamp}/worker_join"
k8s_config = "${var.s3_k8s_config}/config/${local.USER_ID}/${local.ENV_ID}/${var.cluster_name}-${local.target_time_stamp}/config"
worker_nodes = var.node_type == "spot" ? {
for key, instance in data.aws_instances.spot_fleet_worker :
key => {
private_ip = join("", instance.private_ips)
public_ip = join("", instance.public_ips)
runtime = var.k8s_worker[key].runtime
labels = var.k8s_worker[key].node_labels
id = join("", instance.ids)
ami = aws_launch_template.worker["${key}"].image_id
ubuntu_version = var.k8s_worker["${key}"].ubuntu_version
instance_type = var.k8s_worker["${key}"].instance_type
}
} : {
for key, instance in aws_instance.worker :
key => {
private_ip = instance.private_ip
public_ip = instance.public_ip
runtime = var.k8s_worker[key].runtime
labels = var.k8s_worker[key].node_labels
id = instance.id
ami = instance.ami
ubuntu_version = var.k8s_worker["${key}"].ubuntu_version
instance_type = var.k8s_worker["${key}"].instance_type
}
}
worker_node_ids = join(" ", [for node in local.worker_nodes : node.id])
worker_node_ips_public = join(" ", [for node in local.worker_nodes : node.public_ip])
worker_node_ips_private = join(" ", [for node in local.worker_nodes : node.private_ip])
master_ip = var.node_type == "spot" ? join("", data.aws_instances.spot_fleet_master["enable"].public_ips) : aws_instance.master["enable"].public_ip
master_ip_public = var.k8s_master.eip == "true" ? aws_eip.master["enable"].public_ip : local.master_ip
external_ip = var.k8s_master.eip == "true" ? aws_eip.master["enable"].public_ip : ""
master_instance_id = var.node_type == "spot" ? join("", data.aws_instances.spot_fleet_master["enable"].ids) : aws_instance.master["enable"].id
master_local_ip = var.node_type == "spot" ? join("", data.aws_instances.spot_fleet_master["enable"].private_ips) : aws_instance.master["enable"].private_ip
k8s_worker_ondemand = var.node_type == "ondemand" ? var.k8s_worker : {}
k8s_worker_spot = var.node_type == "spot" ? var.k8s_worker : {}
master_ami = var.k8s_master.ami_id != "" ? var.k8s_master.ami_id : data.aws_ami.master.image_id
master_instance_type = var.k8s_master.instance_type
hosts_worker_node = [for key, value in local.worker_nodes : "${var.cluster_name}_node_${key}=${value.private_ip}"]
hosts_master_node = ["${var.cluster_name}_controlPlane_1=${local.master_local_ip}"]
hosts = concat(local.hosts_master_node, local.hosts_worker_node)
}