Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

AS3 pool members using a list

mihaic
MVP
MVP

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.

1 ACCEPTED SOLUTION

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}
          }]

  

View solution in original post

4 REPLIES 4

Leslie_Hubertus
Community Manager
Community Manager

Hi @mihaic - @Sebastian_Maniak may be able to help here. 🙂

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}
          }]

  

thanks!!!!!!

It worked.

I don't know how I haven't tried this option before.