forked from ViktorUJ/cks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2_worker_ondemand.tf
48 lines (43 loc) · 1.74 KB
/
ec2_worker_ondemand.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
resource "aws_instance" "worker" {
for_each = local.k8s_worker_ondemand
iam_instance_profile = aws_iam_instance_profile.server.id
associate_public_ip_address = "true"
ami = each.value.ami_id != "" ? each.value.ami_id : data.aws_ami.worker["${each.key}"].image_id
instance_type = each.value.instance_type
subnet_id = local.subnets[each.value.subnet_number]
key_name = each.value.key_name != "" ? each.value.key_name : null
security_groups = [aws_security_group.servers.id]
lifecycle {
ignore_changes = [
instance_type,
user_data,
root_block_device,
key_name,
security_groups
]
}
user_data = base64encode(templatefile("template/boot_zip.sh", {
boot_zip = base64gzip(templatefile(each.value.user_data_template, {
worker_join = local.worker_join
k8s_config = local.k8s_config
k8_version = each.value.k8_version
runtime = each.value.runtime
runtime_script = file(each.value.runtime_script)
task_script_url = each.value.task_script_url
node_name = each.key
node_labels = each.value.node_labels
ssh_private_key = each.value.ssh.private_key
ssh_pub_key = each.value.ssh.pub_key
ssh_password = random_string.ssh.result
ssh_password_enable = var.ssh_password_enable
}))
}))
tags = local.tags_all
root_block_device {
volume_size = each.value.root_volume.size
volume_type = each.value.root_volume.type
delete_on_termination = true
tags = local.tags_all
encrypted = true
}
}