terraform-provider-rancher2
terraform-provider-rancher2 copied to clipboard
How to remove nodes for Custom provider
I am using rancher2 provider to provision kuberntes cluster.
Instead of using rancher2_node_pool
, I am using the Custom
provider to provision my nodes on aws because I wanted to do some other initialisation work.
Down the bottom is my code to provision the cluster. It worked well, but the problem is how do I remove nodes? I can reduce the number of aws instances, but the nodes would still show up in the UI.
resource "aws_instance" "multi-worker-nodes" {
count = 3
#ami = data.aws_ami.ubuntu.id
#ami = "ami-22a44040"
ami = var.images["ubuntu"]
instance_type = var.instance_type["worker"]
key_name = aws_key_pair.rke-node-key.id
iam_instance_profile = aws_iam_instance_profile.rke-aws.name
vpc_security_group_ids = [aws_security_group.rancher-node-secgrp.id]
tags = local.cluster_id_tag
subnet_id = "${data.aws_subnet.rancher-subnet[count.index % length(data.aws_subnet.rancher-subnet)].id}"
root_block_device {
#device_name = "/dev/sda1"
volume_size = "40"
volume_type = "gp2"
delete_on_termination = true
}
provisioner "remote-exec" {
connection {
host = coalesce(self.public_ip, self.private_ip)
type = "ssh"
user = "ubuntu"
private_key = tls_private_key.node-key.private_key_pem
}
inline = [
"sudo mv /var/lib/apt/lists /var/lib/apt/lists.old",
"sudo apt-get update",
"curl https://releases.rancher.com/install-docker/18.09.sh | sh",
"sudo usermod -a -G docker ubuntu",
"sudo apt-get install -y salt-minion",
"sudo bash -c 'echo master: salt.mumba.cloud >> /etc/salt/minion'",
"sudo service salt-minion restart",
"${rancher2_cluster.rancher_development.cluster_registration_token.0.node_command} --worker"
]
}
}