Skip to main content

Trick to Making Terraform Wait for AutoScaling Groups Instances to Ready

When using Terraform, it's not possible to know when the EC2 instances that are part of an AutoScaling Group are completely ready without using an ELB. And by completely ready, I mean we know the instances have finished running their cloud-init process (AKA userdata).  See this Github issue for more details. But if we have access to the instances in the VPC, there's a workaround!

To do this, you'll create your AutoScaling Group as usual:

resource "aws_autoscaling_group" "cluster" {
desired_capacity = "${var.ec2-instance-count}"
launch_configuration = "${aws_launch_configuration.cluster.id}"
max_size = "${var.ec2-instance-count}"
min_size = 1
name = "cluster"
vpc_zone_identifier = var.subnet-ids
tag {
key = "Name"
value = "cluster"
propagate_at_launch = true
}
}

Then, we'll create a data source that's meant to wait for the AutoScaling group to be created:

data "aws_instances" "cluster" {
filter {
name = "tag:aws:autoscaling:groupName"
values = ["${aws_autoscaling_group.openshift-masters.name}"]
}
}

This data source will wait for the AutoScaling Group to be ready before populating the instance information.

Now for the trick...

Create a Terraform module and feed the data source as an input to that module. The variable should accept a list as input:

variable "cluster-ips" {
type = list(string)
}
 
The calling the module should look something like this:
module "cluster-wait-for" {
source = "./cluster-wait-for"
cluster-ips = "${data.aws_instances.cluster}"
ec2-instance-count = "${var.ec2-instance-count}"
}

 And now, inside that module, we create a null_resource to ssh to the nodes and wait for cloud-init to finish:
resource "null_resource" "wait-for-cloud-init-cluster" {
count = "${var.ec2-instance-count}"
connection {
type = "ssh"
user = "ec2-user"
host = "${var.cluster-ips[count.index]}"
private_key = "${file(var.ec2-key-location)}"
}
provisioner "remote-exec" {
inline = [
"sudo cloud-init status --wait"
]
}

triggers = {
workers = "${join(",", sort(var.cluster-ips))}"
}
}


Now, whenever the AutoScaling Group is updated (thanks to the trigger) this resource will ssh to the instances and wait until cloud-init is finished running.

Comments

  1. Play Slots | Slots Casino Games | Shootercasino
    Play 더킹카지노 free online slot games including Slots, Blackjack and Roulette. Get your Sign Up Bonus. Choose one of our 10+ 샌즈카지노 games and claim your 10bet Welcome Bonus.

    ReplyDelete
  2. Harrah's Cherokee Casinos - JCM Hub
    Harrah's Cherokee Casinos 창원 출장안마 Harrah's Cherokee is operated 평택 출장샵 by 의왕 출장안마 Boyd 파주 출장마사지 Gaming and is part of the Eastern Band 밀양 출장샵 of the Cherokee Nation and operated by Caesars

    ReplyDelete
  3. Nintendo Switch Online - Japan's Only Gambling Hub
    The Japanese sports betting market is expected to mature 우리카지노 considerably, ₹64,420.00 · ‎In stock

    ReplyDelete
  4. Many mobile casinos also use social media websites as a degree of contact for buyer support. Looking on the ‘Tweets & Replies’ a part of} a mobile casino’s Twitter feed normally a|could be a} good approach to see how they work to 먹튀사이트 먹튀프렌즈 resolve issues. In order to be licensed to operate a mobile on line casino must prove that it's protected and safe to deal with real cash bets.

    ReplyDelete
  5. This bonus is usually a share of the quantity you deposit, and it might be 100% or more. For example, should you deposit $500 and acquire a 100% deposit bonus, your account will be 1xbet korea credited with a total of $1,000. These bonuses have phrases and conditions utilized, which you should learn beforehand.

    ReplyDelete
  6. From the method, we will to} see the usual deviation is proportional to the casino.edu.kg sq. root of the variety of rounds performed, while the anticipated loss is proportional to the variety of rounds performed. As the variety of rounds increases, the anticipated loss increases at a much faster fee. This is why it is unimaginable for a gambler to win in the long term|the lengthy run}. It is the high ratio of short-term commonplace deviation to anticipated loss that fools gamblers into considering that they will win. The calculation of the roulette house edge is a trivial exercise; for different games, this is not often the case. Combinatorial analysis and/or pc simulation is necessary to finish the task.

    ReplyDelete
  7. Commission is calculated as a share of the operators' winnings generated by way of the company's Live Casino offering. Also, Live Casino is seen as more participating and reliable than graphical random number generator games like slots. With progressive games like Lightning Roulette, Casino Hold’em and Evolution Live Blackjack, you’re never short of of|wanting} stay gaming entertainment at JackpotCity Casino. ITech Labs is a testing and certification lab for Online Gaming systems, focusing on compliance, software program high 온라인카지노 quality, reporting and delivery. Having testing accomplished by iTech Labs ensures that games and gaming systems comply with all relevant requirements, and that they're truthful, dependable and resilient. All front-line personnel are additionally participating in specifically tailored training designed to reinforce their professionalism in each gaming and communication expertise.

    ReplyDelete

Post a Comment