-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing a variable of type "list" compose with the output from a module to another module #13103
Comments
Hi @mario21ic, thanks for the issue! If you use the interpolation function
|
Hello @grubernaut, thanks for the answer, but, yes I still giving the same error, I followed the guide https://www.terraform.io/docs/configuration/interpolation.html |
Using
I'll try setting the input variables to the |
Hello @grubernaut , thanks for the attention, the case is uploaded in https://github.com/mario21ic/terraform-aws-vpc-elb/blob/master/main.tf#L32 |
Hey folks - we ran into this same issue in one of our configs. I cooked up a minimal repro case here before I found this issue - it looks very similar to @mario21ic's description: https://github.com/phinze/terraform-issues/tree/master/should-be-a-list In my experimentation it seems that the key bit is that the output of the module generating the list needs to be computed. See the |
@mario21ic try to add [] in resource
|
Hi :-) Any updates about this issue ? data "terraform_remote_state" "vpc_rs" {
backend = "s3"
config {
bucket = "${var.vpc_rs_bucket}"
key = "${var.vpc_rs_key}"
region = "${var.region}"
}
}
module "asg" {
source = "../modules/asg/"
owner = "${var.owner}"
lc_name = "test"
lc_ssh_key_name = "${var.ssh_key_name}"
asg_name = "test asg"
asg_max_size = "1"
asg_min_size = "1"
asg_desired_capacity = "1"
asg_vpc_zone_identifier = ["${split( ",", data.terraform_remote_state.vpc_rs.private_subnet)}"]
}
output "test_list" {
value = "${split( ",", data.terraform_remote_state.vpc_rs.private_subnet)}"
} During a plan or a validate I got the following error :
If I comment the module bit I got following in the output :
Did I do something wrong ? Edit : Actually I did, it's now working. Sorry for the noise. |
@renaudhager what did you do wrong that code? I am getting a similar issue!!! |
@samof76 I've fixed similar issue. When you pass this list to resource inside module you have to wrap it in square brackets again, eg: # module/main.tf
variable "list_sg" {
type = "list"
}
varaible "list_subnets" {
type = "list"
}
resource "aws_smthing" "example" {
...
security_group_ids = ["${var.list_sg}"] # won't work without brackets
subnet_ids = ["${var.list_subnets}"]
...
}
# example.tf
module "example" {
source "./module"
list_sg = [
"${data.data.terraform_remote_state.security_group_1}",
"${data.data.terraform_remote_state.security_group_2}"
]
list_subnets = ["${split(",",data.terraform_remote_state.subnets)}"]
} |
I can confirm that the workaround suggested by @ayarmoluk17 works as expected (with terraform 0.11.0). Is this the idiomatic solution, or a workaround based on another bug, or something in between? Will the code like that will continue to work after this bug (or some other bug) is fixed? |
Having the same issue. Seems to stem from constructing a list from the outputs of another module. |
I have encountered this issue (unsurprisingly when trying to pass around lists of subnets also) I was using version While the workaround put forward by @ayarmoluk17 seems to "work" its got a bit of an annoying caveat. For example, when I use it in an ASG: resource "aws_autoscaling_group" "foo_asg" {
...
vpc_zone_identifier = ["${var.subnets}"]
...
} I get something like this in the
As you can see Terraform has produced a list with one element, that element being the comma separated list as a string. This ends up working well and good, it looks like somewhere (I'm guessing on the AWS end) it gets "corrected". The problem is when you then run the next
This will happen every time Other than the niggle that there are changes and (identity) actions that are taken each time resource "aws_alb" "foo-alb" {
...
subnets = ["${var.subnets}"]
...
} Again the plan for this looks like the following:
Unfortunately while it was workable in the ASG case, attempting to apply this plan results in the following error:
I might also just point out that the 3 subnets were indeed in different availability zones, so it should have worked. To work around this issue, I thought "oh, its interpreting the list as a comma separated string, so hopefully I just need to replace Anyway what did eventually work for me was So: ASG: resource "aws_autoscaling_group" "foo_asg" {
...
vpc_zone_identifier = ["${split(",", join(",", var.subnets))}"]
...
} ALB: resource "aws_alb" "foo-alb" {
...
subnets = ["${split(",", join(",", var.subnets))}"]
...
} Both have the desired plans:
And applying the plan works, the ALB is successfully created. The |
We have a similar issue with a slight variation (?) from above:
|
Faced the same issue when trying to pass around list of objects (maps) such as those for the connection_string property on the Azure App Service:
and later:
always gives the error: When trying the workaround with the brackets in the referenced App Service module it will show an error that the properties are not properly set for the connection_string input object (connection_string.0.name, connection_string.0.type, connection_string.0.value). So looks like the workaround is not valid for list of objects... |
Hi all, Although we've not directly verified this one yet, I strongly suspect it will be fixed by the improved language interpreter coming in the next major release. Although it's not directly one of the line items in that article, the changes made to support things like rich types in module inputs and outputs have improved the robustness of how Terraform thinks about complex types (types constructed from other types, like lists), including allowing it to represent "unknown-ness" without losing track of the fact that the value is a list, which is the root cause of the bug here. I've updated the labels here to remind us to look at this issue again when we're doing pre-release testing. |
@appelgriebsch I have the Connection string values working in Azure using Variables
|
@whytoe yes, that will still work and I use this way for scenarios I have the required information for the connection string in my var-file anyway... but for connection strings to e.g. CosmosDB, ServiceBus, Storage Account, etcpp. I will need access keys that are not available upfront and so I have to refer to output from another tf module... |
@appelgriebsch ya for sure, I just saw the app_service example and thought I would try and help you out in the interim |
Hi all! Sorry for the long silence here. This issue is covering the same root cause as #12263, which I've closed today since it appears to be fixed in v0.12.0-alpha1. We do still have issue #19140 open related to the problem of updating the common workaround of wrapping an extra level of list brackets around the expression, which we'll aim to address separately before v0.12.0 final. |
Change length() to use format described in hashicorp/terraform#13103 for var.allowed_security_groups
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. |
Hi there, I have a problem passing variable type list from a module to another module, it is compose with the output from another module.
Example:
./tfmodules/vpc/main.tf
./tfmodules/elb/main.tf
./main.tf
I have got the follow error:
But is worked if I put with this way:
./main.tf
Terraform Version
v0.9.1
Affected Resource(s)
Terraform Configuration Files
See above
Debug Output
See above
Expected Behavior
Catch the two values to compose the variable of type list
Actual Behavior
module.elb.aws_elb.my_elb: subnets: should be a list
Steps to Reproduce
See above
The text was updated successfully, but these errors were encountered: