-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.tf
89 lines (77 loc) · 2.9 KB
/
worker.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
data "aws_ami" "eks-worker" {
filter {
name = "name"
values = ["amazon-eks-node-${aws_eks_cluster.rakam.version}-v*"]
}
most_recent = true
owners = ["602401143452"] # Amazon EKS AMI Account ID
}
# This data source is included for ease of sample architecture deployment
# and can be swapped out as necessary.
data "aws_region" "current" {}
# EKS currently documents this required userdata for EKS worker nodes to
# properly configure Kubernetes applications on the EC2 instance.
# We implement a Terraform local here to simplify Base64 encoding this
# information into the AutoScaling Launch Configuration.
# More information: https://docs.aws.amazon.com/eks/latest/userguide/launch-workers.html
locals {
rakam-node-userdata = <<USERDATA
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh --apiserver-endpoint '${aws_eks_cluster.rakam.endpoint}' --b64-cluster-ca '${aws_eks_cluster.rakam.certificate_authority.0.data}' '${var.cluster-name}'
USERDATA
}
resource "aws_launch_configuration" "rakam" {
associate_public_ip_address = true
iam_instance_profile = "${aws_iam_instance_profile.rakam-node.name}"
image_id = "${data.aws_ami.eks-worker.id}"
instance_type = "${var.instance-type}"
name_prefix = "terraform-eks-worker"
security_groups = ["${aws_security_group.rakam-node.id}"]
user_data_base64 = "${base64encode(local.rakam-node-userdata)}"
lifecycle {
create_before_destroy = true
}
}
# AutoScaling Group that actually launches EC2 instances based on the AutoScaling Launch Configuration.
resource "aws_autoscaling_group" "rakam" {
desired_capacity = "${var.instance-capacity}"
launch_configuration = "${aws_launch_configuration.rakam.id}"
max_size = "${var.instance-capacity-max}"
min_size = "${var.instance-capacity-min}"
name = "terraform-eks-workers"
vpc_zone_identifier = "${aws_subnet.rakam.*.id}"
tag {
key = "Name"
value = "terraform-eks-workers"
propagate_at_launch = true
}
tag {
key = "kubernetes.io/cluster/${var.cluster-name}"
value = "owned"
propagate_at_launch = true
}
enabled_metrics = [
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupMaxSize",
"GroupMinSize",
"GroupPendingInstances",
"GroupStandbyInstances",
"GroupTerminatingInstances",
"GroupTotalInstances",
]
}
# TODO: Policy to scale the cluster
/* resource "aws_autoscaling_policy" "rakam" {
name = "rakam-cpu-autoscaler"
adjustment_type = "ChangeInCapacity"
autoscaling_group_name = "${aws_autoscaling_group.rakam.name}"
policy_type = "TargetTrackingScaling"
target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"
}
target_value = 30.0
}
}*/