Hi,
I have two modules:
module 1 loadbalancer:
...
output "backendAddressPoolId" {
value = "${azurerm_lb_backend_address_pool.backendAddressPool.id}"
}
module 2 virtual machine:
...
variable "lbBackendAddressPoolIds" {
type = "list"
default = []
}
resource "azurerm_network_interface" "nic" {
count = "${var.count}"
name = "${var.prefix}-nic-${var.name}-${count.index+1}"
location = "${var.location}"
resource_group_name = "${var.resourceGroupName}"
ip_configuration {
name = "ipConfigNode"
subnet_id = "${var.subnetId}"
private_ip_address_allocation = "Dynamic"
load_balancer_backend_address_pools_ids = "${var.lbBackendAddressPoolIds}"
}
}
If I pass the output of the first module to the second module as shown below:
module "loadBalancer" {
source = "module1"
}
module "vm" {
source = "module2"
lbBackendAddressPoolIds = ["${module.loadBalancer.backendAddressPoolId}"]
}
Then I get the following error on terraform plan command
$ terraform plan
There are warnings and/or errors related to your configuration. Please
fix these before continuing.
Errors:
* azurerm_network_interface.nic: ip_configuration.0.load_balancer_backend_address_pools_ids: should be a list
I noticed that if I hard code the value in output then it all works without any errors!
module 1 loadbalancer with hardcoded output value:
...
output "backendAddressPoolId" {
value = "test123"
}
Note sure why using a computed value in the list is failing. Any help will be appreciated!
Terraform Version: v0.8.7
Hi @ordinaryworld! This is some confusing behavior, I agree...
My guess (not actually tested) is that the computed-ness of the list is causing Terraform to see it as a string due to some details of how Terraform currently represents computed values internally.
You might be able to trick Terraform into doing the right thing here by presenting the variable as an interpolation into a list, like this:
load_balancer_backend_address_pools_ids = ["${var.lbBackendAddressPoolIds}"]
@apparentlymart Thanks! That worked! Just wondering if this is this documented somewhere?
@ordinaryworld,
This is in the Interpolation documentation, under the "User list variables" heading.
I'm not entirely certain what we can do to make this easier to spot, the error is precise.
@apparentlymart, do you happen to know of there's enough context at the point of the error to be able to suggest wrapping the interpolation in [ ]?
I see something similar in that I can't take a module output that is a list and use it as a list input for another module. No amount of [ ] fixes.
$ terraform --version
Terraform v0.10.4
I am facing the same thing when using Terraform v0.11.1.
I can get around the problem by adding [] around the variable in the module that receives the list input as a string, however, I have trouble on how to manage this when the source does not define the variable explicitly and sends an empty array instead. Any suggestions or workarounds would be appreciated.
Agreed. This is a total pain. Would love to be able to pass lists through to a module
👍
module_main.tf
resource "aws_mq_broker" "default" {
broker_name = "${var.amazonmq_broker_name}"
engine_type = "${var.amazonmq_engine_type}"
engine_version = "${var.amazonmq_engine_version}"
host_instance_type = "${var.amazonmq_instance_type}"
publicly_accessible = "${var.amazonmq_publicly_accessible}"
security_groups = "${var.amazonmq_security_groups}"
user {
console_access = "${var.amazonmq_user_console_access}"
groups = "${var.amazonmq_user_groups}"
password = "${var.amazonmq_user_password}"
username = "${var.amazonmq_user_username}"
}
}
module_variables.tf
[...]
variable "amazonmq_security_groups" {
type = "list"
}
environment_main.tf
[...]
module "amazonmq" {
source = "../../modules/amazonmq"
amazonmq_broker_name = "${var.amazonmq_broker_name}"
amazonmq_security_groups = "${list(module.vpc.vpc_sg_default)}"
amazonmq_user_password = "${var.amazonmq_user_password}"
amazonmq_user_username = "${var.amazonmq_user_username}"
}
Where ${module.vpc.vpc_sg_default} is a string gathered from:
[...]
output "vpc_sg_default" {
value = "${aws_default_security_group.default.id}"
}
As @horsey has mentioned above, the bracket trick works fine when list is not empty.
module_main.tf
resource "aws_mq_broker" "default" {
[...]
security_groups = ["${var.amazonmq_security_groups}"]
[...]
Not sure why we need to add [.....], but worked like a charm. :)
Workaround to send the empty list issue - I used compact and it will reduces the list from [""} to []
source_application_security_group_ids =["${compact(split(",", "${lookup(var.security_rules_list[count.index], "source_application_security_group_ids", "")}"))}"]
I had the same issue, adding the [ ] to the resource solve the issue.
So from this
```resource "aws_lb" "lb" {
name = "${upper(var.aws_region_code)}-${upper(var.aws_project_code)}-ALB-${var.alb_number}"
load_balancer_type = "application"
internal = "${var.lb_internal}"
security_groups = "${var.lb_security_groups}" <----- Issue Here
[...]
}
**To this**
```resource "aws_lb" "lb" {
[...]
security_groups = ["${var.lb_security_groups}"] <----- Fixed Here
[...]
}
Hi all!
The Terraform v0.12.0-alpha1 release includes the initial fix for this problem, allowing a list with unknown elements to pass through module boundaries while retaining its type as a list. This means the strange workaround of adding an extra level of list brackets is no longer needed, and in fact must no longer be used because it leads to Terraform understanding the value as a list of lists, rather than a single list.
As noted in #19140, as of the alpha1 release the error message for having the redundant brackets is not particularly helpful. We're hoping to introduce a more specific, actionable error message before v0.12.0 final, but either way this is also a change that we intend to fix automatically as part of the configuration migration tool that will be included in v0.12.0 final, thus making the fix easy once Terraform has detected and reported the problem.
Since the original problem reported here is now fixed in the master branch, and we have #19140 covering the remaining usability problem, I'm going to close this out. Thanks for reporting this, and sorry for the delay in getting it fixed.
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
I am facing the same thing when using Terraform v0.11.1.
I can get around the problem by adding [] around the variable in the module that receives the list input as a string, however, I have trouble on how to manage this when the source does not define the variable explicitly and sends an empty array instead. Any suggestions or workarounds would be appreciated.