# Invalid value for module argument

**URL:** <https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823>\
**Category:** Terraform\
**Created:** [August 14, 2020, 12:06pm UTC](https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823 "2020-08-14T12:06:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [August 14, 2020, 12:06pm UTC](https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823/1 "2020-08-14T12:06:51Z")

</div>

Hello,

In one module (called module1) I have this code:

```auto
data "openstack_networking_port_v2" "public_subnet_dhcp_ports" {
  depends_on = [openstack_networking_subnet_v2.public_subnet]
  count = var.network_internal ? 0 : 1
  network_id = openstack_networking_network_v2.public_network[count.index].id
  device_owner = "network:dhcp"
}

// All outputs about dhcp ports for internal subnet
output "dhcp_ports" {
  value = data.openstack_networking_port_v2.subnet_dhcp_ports
  description = "Output of object openstack_networking_port_v2 filtered for DHPC for internal subnet"
}

```

In another module (called module2), I have this code:

```auto
variable "dhcp_ports" {
  type = list(string)
  description = "List of DHCP ports used by OpenStack"
}

resource "netbox_ipam_ip_addresses" "netbox_dhcp_ips" {
  for_each = var.dhcp_ports
  address = format("%s/24", each.value.all_fixed_ips[0])
  description = "IP used by internal OpenStack DHCP"
  tenant_id = var.netbox_tenant_id
  tags = var.tags
  status = "active"
}

```

When I called the module2 with info from the module1, I used this:

```auto
dhcp_ports = tolist(module.tenant_infra-test_internal_01.dhcp_ports.*.all_fixed_ips)

```

During the execution, I have this error:

```auto
Error: Invalid value for module argument
  on infra-test.tf line 103, in module "tenant_infra-test_reserved_ips_internal_01":
 103: dhcp_ports = tolist(module.tenant_infra-test_internal_01.dhcp_ports.*.all_fixed_ips)
The given value is not suitable for child module variable "dhcp_ports" defined
at
.terraform/modules/tenant_infra-test_reserved_ips_internal_01/variables.tf:18,1-22:
incorrect list element type: string required.

```

What’s wrong ?

---

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [August 14, 2020, 12:22pm UTC](https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823/2 "2020-08-14T12:22:30Z")

</div>

I replaced the type from list(string) to list.  
Now I have this message:

```auto
The given "for_each" argument value is unsuitable: the "for_each" argument
must be a map, or set of strings, and you have provided a value of type list
of list of string.
``
```

---

<div class="post-metadata">

**Author:** ![alisdair](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/alisdair/32/4227_2.png) [@alisdair](https://discuss.hashicorp.com/u/alisdair)\
**Post date:** [August 17, 2020, 3:57pm UTC](https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823/3 "2020-08-17T15:57:12Z")

</div>

The error message here indicates that you have a list of list of strings, which makes sense to me:

- The input variable is set to `dhcp_ports.*.all_fixed_ips`, i.e. a list of the `all_fixed_ips` values for all resources
- The `all_fixed_ips` attribute of an `openstack_networking_port_v2` is a `list(string)`

Since you are using `count` to conditionally create the resource, instead you may want to write `dhcp_ports[0].all_fixed_ips`. This will return a single `list(string)`, which should match your module’s (correct) original input variable type requirement.

---

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [August 21, 2020, 2:39pm UTC](https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823/4 "2020-08-21T14:39:51Z")

</div>

I changed the module2 with:

```auto
variable "dhcp_ports" {
  type = list
  description = "List of DHCP ports used by OpenStack"
}

resource "netbox_ipam_ip_addresses" "netbox_dhcp_ips" {
  count = length(var.dhcp_ports)
  address = format("%s/24", var.dhcp_ports[count.index])
  description = "IP used by internal OpenStack DHCP"
  tenant_id = var.netbox_tenant_id
  tags = var.tags
  status = "active"
}

```

Now I have this error:

```auto
Error: More than one openstack_networking_port_v2 found (3)
  on .terraform/modules/.../main.tf line 70, in data "openstack_networking_port_v2" "subnet_dhcp_ports":
  70: data "openstack_networking_port_v2" "subnet_dhcp_ports" {

```

The data openstack\_networking\_port\_v2 in module1 will find several dhcp ports which is normal.  
I would like to get this list of openstack\_networking\_port\_v2 objects.  
For each of them I would like to extract the `all_fixed_ips` which is a list of string (IP).

How to accomplish this ?

---

<div class="post-metadata">

**Author:** ![smutel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/smutel/32/2687_2.png) [@smutel](https://discuss.hashicorp.com/u/smutel)\
**Post date:** [September 2, 2020, 2:59pm UTC](https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823/5 "2020-09-02T14:59:42Z")

</div>

Need more help on this topic please.

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [September 2, 2020, 5:50pm UTC](https://discuss.hashicorp.com/t/invalid-value-for-module-argument/12823/6 "2020-09-02T17:50:46Z")

</div>

Hi @smutel,

Your new question seems to be about the behavior of the OpenStack provider in particular, rather than about Terraform in general, so unfortunately fewer people in this particular category are familiar with it.

It might help to start a new topic in [the Terraform Providers](https://discuss.hashicorp.com/c/terraform-providers/31) forum category. Unfortunately I don’t think the OpenStack provider is as commonly used as some others so I can’t be certain that there will be other folks familiar with that provider watching that category, but I think it’s still more likely to be seen there (with an appropriate new subject line describing the new problem) than as a follow-up to a general question about the Terraform language.
