For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

mihaic's avatar
Apr 06, 2023
Solved

AS3 pool members using a list

I have started to play with AS3. I've tried some examples and they work fine.

But I have counter a problem. Maybe it is not possible.

I am using Terraform and AS3 data template to configure a virtual server. 

data template_file "init" {
  template = file("example.tpl")
  vars = {
    TENANT = var.TENANT
    VIP = var.VIP
    POOL = var.POOL
    LB_MODE = var.LB_MODE
    MONITOR = var.MONITOR
    MEMBERS = jsonencode(var.MEMBERS)
    }
  }
resource "bigip_as3"  "as3-deploy-tenant" {
     as3_json = data.template_file.init.rendered
}

MEMBERS is a list :

variable "MEMBERS" {
  type    = list(string)
  default = []
}
MEMBERS = ["1.1.1.1","9.9.9.9"]

 I am using jsonencode() function as it seems this is used for lists in Terraform.

It seemed it did not work. I get this:

Planning failed. Terraform encountered an error while generating this plan.

│ Error: "as3_json" contains an invalid JSON: invalid character '1' after array element

│ with bigip_as3.as3-deploy-tenant,
│ on main.tf line 25, in resource "bigip_as3" "as3-deploy-tenant":
│ 25: resource "bigip_as3" "as3-deploy-tenant" {

It works if MEMBERS is just a string variable. Or if I choose just the first element of the list for example without the jsonencode function.

But I was wondering if I could use a list because I ma trying to do this in my template file:

"${POOL}": {
"class": "Pool",
"loadBalancingMode":"${LB_MODE}",
"monitors": [
"${MONITOR}"
],
"members": [
{
"servicePort": 80,
"serverAddresses": [
"${MEMBERS}"
]
}
]
}

Thanks in advance for any hint you might have.

  • Try removing the square brackets and quotes around the ${MEMBERS} variable in the JSON. I spotted this example from one of Sebastian_Maniak 's guides:

    in the module:
        MY_POOLMEMBERS = jsonencode(var.pool_members)
    
    in the json:
              "members": [{
                "servicePort": 80,
                "shareNodes": true,
                "serverAddresses": ${MY_POOLMEMBERS}
              }]

      

4 Replies