Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem to add pool atttachments with for_each #876

Open
Hoonigan-013 opened this issue Sep 29, 2023 · 6 comments
Open

Problem to add pool atttachments with for_each #876

Hoonigan-013 opened this issue Sep 29, 2023 · 6 comments

Comments

@Hoonigan-013
Copy link

Hoonigan-013 commented Sep 29, 2023

Hello,

I am using a different for_each in pool resources to create more than one pool with the same resource and another for_each in node to create new nodes with the same resources. So, if I try to use any of these two for_each in pool attachment I receive index error because pool is using one for_each and nodes another for_each.

Could you help me, how can I solve this issue?
Is it possible create pool attachments with for in both resources (pool and node)?

@pgouband
Copy link
Collaborator

pgouband commented Oct 2, 2023

Hi @Hoonigan-013,

Can you share your TF file with the for_each?

@Hoonigan-013
Copy link
Author

Hi, @pgouband

resource "bigip_ltm_pool" "pool" {
  for_each = var.vs_creation
  name                   = "/Part/${format("%s-%s-%s","pool","${each.value.service_name}","${each.value.pool_port}")}"
  load_balancing_mode    = "${each.value.pool_lb_mode}"
  minimum_active_members = 1
  monitors               = "${each.value.pool_monitor}"
  slow_ramp_time         = 0
  depends_on             = [bigip_ltm_node.node]
}

resource "bigip_ltm_pool_attachment" "attach_node" {
  for_each = var.node_creation
  pool = "${bigip_ltm_pool.pool[each.key].name}"
  node = "${bigip_ltm_node.node[each.key].name}:${each.value.pool_port}"
}


resource "bigip_ltm_node" "node" {
  for_each = var.node_creation
  name             = "/Part/${each.value.node_name}"
  #name             = "/Part/${var.node_name}"
  address          = "${each.value.node_address}"
  connection_limit = "0"
  dynamic_ratio    = "1"
  monitor          = "${each.value.node_monitor}"
  rate_limit       = "disabled"

Just to explain Why I am using different for_eachs. In vs_creation there's attributes to create all pool and vs configuration and in node_creation all configuration to node creation. It was separeted because node is a string type and when I need to create more than one node with string variable inside vs_creation it is not possible create more than one node. So, the ideia is create a for each to nodes to create how many nodes I need and after it create pool attachment with the same quantity as nodes creation.

For example:
One pool creation
Two nodes creation
Two attachment creation

So, the nodes will be attached in that single pool that was created.

This way, I receive errors with this each values because they belongs a var.vs_creation not var.node_creation :
"${bigip_ltm_pool.pool[each.key].name}"
"${each.value.pool_port}"

This correlation is being the problem for me :(

@pgouband
Copy link
Collaborator

pgouband commented Oct 3, 2023

Hi @Hoonigan-013,

Thanks for sharing.
Could you also share one example of each variable and tfvars?

@Hoonigan-013
Copy link
Author

variables.tf

variable "vs_creation" {
  type = map(object({
    service_name = string
    vs_port         = number
    vs_profile      = list(string)
    vs_persistence  = optional(list(string))
    pool_lb_mode    = string
    pool_monitor    = list(string)
    pool_port       = string
  }))
  default = {
    service_name    = null
    vs_port         = null
    vs_profile      = null
    vs_persistence  = null
    pool_lb_mode    = null
    pool_monitor    = null
    pool_port       = null
  }
}

variable "node_creation" {
  type = map(object({
    node_name       = string
    node_address    = string
    node_monitor    = string
  }))
}

terraform.tfvars

vs_creation = {
01  = {
      service_name    = "test"
      vs_port         = 443
      vs_profile      = ["/Common/tcp", "/Common/http"]
      vs_persistence  = ["/Common/source_addr"]
      pool_lb_mode    = "round-robin"
      pool_monitor    = ["/Common/gateway_icmp"]
      pool_port       = "443"
    } 

node_creation = {
    
    01 = {
      node_name       = "test.hom.si.net"
      node_address    = "172.172.10.249"
      node_monitor    = "/Common/gateway_icmp"
    }

I tried with different for_each because sometimes I need to add more than one node, so using only vs_creation I cannot add more than one node because node address and node name are string type.

@pgouband
Copy link
Collaborator

pgouband commented Oct 4, 2023

Hi @Hoonigan-013,

In the following resource, the for_each is based on node_creation but in node_creation there is no pool_port.

resource "bigip_ltm_pool_attachment" "attach_node" {
  for_each = var.node_creation
  pool = "${bigip_ltm_pool.pool[each.key].name}"
  node = "${bigip_ltm_node.node[each.key].name}:${each.value.pool_port}"
}

Here an example of solution, adding pool_port in node_creation variable.

variables.tf

variable "node_creation" {
  type = map(object({
    node_name       = string
    node_address    = string
    node_monitor    = string
    pool_port       = string
  }))
}

terraform.tfvars

node_creation = {    
    01 = {
      node_name       = "test.hom.si.net"
      node_address    = "172.172.10.249"
      node_monitor    = "/Common/gateway_icmp"
      pool_port       = "443"
    }
}

@arvsss10
Copy link

arvsss10 commented Aug 6, 2024

hi @Hoonigan-013

have you found a workaround in this setup?
I'm also trying to find a way to do multiple for_each statement to create multiple VS and pools using single resource each.

TYIA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants