diff options
Diffstat (limited to 'terraform/asg.tf')
-rw-r--r-- | terraform/asg.tf | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/terraform/asg.tf b/terraform/asg.tf new file mode 100644 index 0000000..8c6e7a0 --- /dev/null +++ b/terraform/asg.tf @@ -0,0 +1,52 @@ +# 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 utilize 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 { + demo-node-userdata = <<USERDATA +#!/bin/bash +set -o xtrace +/etc/eks/bootstrap.sh --apiserver-endpoint '${aws_eks_cluster.sensyne_demo_cluster.endpoint}' --b64-cluster-ca '${aws_eks_cluster.sensyne_demo_cluster.certificate_authority.0.data}' '${var.cluster_name}' +USERDATA +} + +resource "aws_launch_configuration" "sensyne_demo_alc" { + associate_public_ip_address = true + iam_instance_profile = "${aws_iam_instance_profile.sensyne_demo_node.name}" + image_id = "${data.aws_ami.eks-worker.id}" + instance_type = "m4.large" + name_prefix = "sensyne_demo_alc" + security_groups = ["${aws_security_group.sensyne_demo_node.id}"] + user_data_base64 = "${base64encode(local.demo-node-userdata)}" + + lifecycle { + create_before_destroy = true + } +} + +resource "aws_autoscaling_group" "sensyne_demo_asg" { + desired_capacity = 2 + launch_configuration = "${aws_launch_configuration.sensyne_demo_alc.id}" + max_size = 2 + min_size = 1 + name = "sensyne_demo_asg" + vpc_zone_identifier = ["${aws_subnet.sensyne_demo_subnet.*.id}"] + + tag { + key = "Name" + value = "sensyne_demo_asg_worker" + propagate_at_launch = true + } + + tag { + key = "kubernetes.io/cluster/${var.cluster_name}" + value = "owned" + propagate_at_launch = true + } +} + |