terraform-provider-openstack: allowed_address_pairs does not accept list

allowed_address_pairs does not accept (correct?) interpolated parameter.

Terraform Version

0.11

Affected Resource(s)

  • openstack_networking_port_v2

Terraform Configuration Files

First declare 10 ports:

resource "openstack_networking_port_v2" "vip" {
  name = "mytest-${count.index}"
  network_id = "${openstack_networking_network_v2.net-backend.id}"
  admin_state_up = "true"
  count = "10"
}

Next, create port where those 10 addresses are allowed:

resource "openstack_networking_port_v2" "port" {
  name = "mytest"
  admin_state_up = "true"
  network_id = "${openstack_networking_network_v2.net-backend.id}"
  allowed_address_pairs = "${formatlist("{ip_address=\"%v\"}", 
  openstack_networking_port_v2.vip.*.all_fixed_ips.0)}"
}

Actual result

Error: openstack_networking_port_v2.port: allowed_address_pairs: should be a list

If you output the interpolation:

output "mylist" {
  value="${formatlist("{ ip_address=\"%v\" }", openstack_networking_port_v2.vip.*.all_fixed_ips.0)}"
}

you get:

mylist = [
    { ip_address="100.127.172.186" },
    { ip_address="100.127.172.19" },
    { ip_address="100.127.172.180" },
    { ip_address="100.127.172.18" },
    { ip_address="100.127.172.182" },
    { ip_address="100.127.172.184" },
    { ip_address="100.127.172.189" },
    { ip_address="100.127.172.183" },
    { ip_address="100.127.172.179" },
    { ip_address="100.127.172.181" }
]

And if you copypaste this output to the .tf file, it works. But that’s not what you want to do 😃

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 22 (7 by maintainers)

Most upvoted comments

Any chance to move on with this? I’m really pissed off by workarounding this 🙄

@splashx I don’t need this anymore. I can ask my then-employer to use HCL2 …

@michalmedvecky you should use the new syntax of HCL2 (terraform 0.12):

locals {
  some_list_of_ips = [
    "127.0.0.1",
    "127.0.0.2",
    "127.0.0.3"
  ]
}

resource "openstack_networking_port_v2" "test-adp" {
  name           = "some-name"
  count          = "1"
  network_id     = "ef3a3380-931e-45fc-a7b8-6a1ad3bc24ab"
  admin_state_up = "true"
  dynamic "allowed_address_pairs" {
    for_each = local.some_list_of_ips
    content {
      ip_address = allowed_address_pairs.value
    }
  }
}
$ openstack port show some-name --format=json | jq '.allowed_address_pairs'
"ip_address='127.0.0.1', mac_address=''\nip_address='127.0.0.2', mac_address=''\nip_address='127.0.0.3', mac_address=''"

Of course one can use a list of IPs in splat syntax instead of some_list_of_ips.

This issue should be closed.