-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlaunch_template.tf
48 lines (39 loc) · 1.37 KB
/
launch_template.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
data "aws_ssm_parameter" "eks" {
name = format("/aws/service/eks/optimized-ami/%s/amazon-linux-2/recommended/image_id", var.k8s_version)
}
# data "template_file" "user_data" {
# template = file("${path.module}/files/user-data/userdata.tpl")
# vars = {
# CLUSTER_NAME = var.cluster_name,
# CLUSTER_ID = var.cluster_name,
# APISERVER_ENDPOINT = aws_eks_cluster.eks_cluster.endpoint,
# B64_CLUSTER_CA = aws_eks_cluster.eks_cluster.certificate_authority.0.data,
# }
# }
resource "aws_launch_template" "main" {
image_id = data.aws_ssm_parameter.eks.value
name = format("%s-template", var.cluster_name)
update_default_version = true
vpc_security_group_ids = [
aws_eks_cluster.eks_cluster.vpc_config[0].cluster_security_group_id
]
user_data = base64encode(templatefile(
"${path.module}/files/user-data/userdata.tpl",
{
CLUSTER_NAME = var.cluster_name,
CLUSTER_ID = var.cluster_name,
APISERVER_ENDPOINT = aws_eks_cluster.eks_cluster.endpoint,
B64_CLUSTER_CA = aws_eks_cluster.eks_cluster.certificate_authority.0.data,
}
))
iam_instance_profile {
name = aws_iam_instance_profile.nodes.name
}
tag_specifications {
resource_type = "instance"
tags = {
"Name" : var.cluster_name,
"aws-node-termination-handler/managed" = "true"
}
}
}