I have a terraform script where I launch a cluster of ec2 instances and combine them together (specifically for Influx Db). Here is the relevant part of the script:
resource "aws_instance" "influxdata" {
count = "${var.ec2-count-influx-data}"
ami = "${module.amis.rhel73_id}"
instance_type = "${var.ec2-type-influx-data}"
vpc_security_group_ids = ["${var.sg-ids}"]
subnet_id = "${element(module.infra.subnet,count.index)}"
key_name = "${var.KeyName}"
tags {
Name = "influx-data-node"
System = "${module.infra.System}"
Environment = "${module.infra.Environment}"
OwnerContact = "${module.infra.OwnerContact}"
Owner = "${var.Owner}"
}
ebs_block_device {
device_name = "/dev/sdg"
volume_size = 750
volume_type = "io1"
iops = 3000
encrypted = true
delete_on_termination = false
}
user_data = "${file("terraform/attach_ebs.sh")}"
connection {
//private_key = "${file("/Users/key_CD.pem")}" #dev env
//private_key = "${file("/Users/influx.pem")}" #qa env west
private_key = "${file("/Users/influx_east.pem")}" #qa env east
user = "ec2-user"
}
provisioner "remote-exec" {
inline = ["echo just checking for ssh. ttyl. bye."]
}
}
What I'm now trying to do...is taint one instance and then have terraform rebuild it but...what I want it to do is to unmount ebs, detach ebs, rebuild instance, attach ebs, mount ebs.
When I do a terraform taint module=instance it does taint it and then when I go to apply the change, it creates a whole new instance and new ebs volume instead of reattaching the previous one back on the new instance.
I'm also ok with some data loss as this is part of a cluster so when the node gets rebuilt...it should just sync up with the other nodes....
How can one do this with Terraform?