rancher / terraform-provider-rancher2

Terraform Rancher2 provider
https://www.terraform.io/docs/providers/rancher2/
Mozilla Public License 2.0
254 stars 220 forks source link

rancher2_node_pool IP Addresses #325

Open ajchiarello opened 4 years ago

ajchiarello commented 4 years ago

When creating a node pool, is there any way to get the IP addresses of the nodes that have been created? I am using the authorized cluster endpoint feature and need to add my controlplane nodes to my load balancer.

ricanol commented 3 years ago

@ajchiarello I had the same problem, I thought the same way about getting the ips using the rancher2_node_pool, but discover a more effective way using: rancher2_cluster_sync and use its output to get the ips, but I specify the nodes output along with ip_address or external_ip_address, it depends on what you are going to use.

remembering that the output is in list form, even with only 1 host. Below I show an example and how I get the IP address.

resource "rancher2_cluster_sync" "prod" {
  cluster_id =  rancher2_cluster.prod.id
  node_pool_ids = [rancher2_node_pool.nodepool_worker.id]
}

Now we can get the IP of the nodes and use where, I'm just getting the internal ip of my node like this:

rancher2_cluster_sync.prod.nodes[0].ip_address

I hope it helped you!