-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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 data source as a list element from a calling module messes up the list #17292
Comments
Hi @horsey, Unfortunately the configuration you have wasn't intended to work that way. The We're working on configuration language improvements at the moment which should hopefully make the configuration more clear, and prevent things like this from "accidentally" working while providing better errors. Once we have that in place, we can work on the possibility of passing configuration blocks around somehow, as it's becoming an often requested feature in more complex configurations. |
Hello @jbardin, |
Right now the best way is to pass the individual values into separate configuration blocks.
|
@jbardin |
No there is not currently any way to iterate within the configuration. In future versions we may have the constructs to iterate over the values directly within the configuration. |
Thanks @jbardin! |
After two months with terraform constantly hitting by issues like this (when something so obvious and intuitive yet for some reason doesn't work though seems like had to fit from the very first releases), I finally realized what terraform reminds me. It is this game https://www.youtube.com/watch?v=V_DtccNhLTs&t=35s which intentionally being designed to piss you off. |
So my 2 cents as to the possible workaround... I found using ALB resources instead of ELB, with some portion of magic, would allow to do it. Module usage: module "instance_with_lb" {
# ...
lb_listeners = [
{
"instance_port" = 8080
"instance_protocol" = "HTTP"
"lb_port" = 80
"lb_protocol" = "HTTP"
},
{
"instance_port" = 8080
"instance_protocol" = "HTTP"
"lb_port" = 443
"lb_protocol" = "HTTPS"
"ssl_certificate_id" = "${aws_iam_server_certificate.fake_cert.arn}"
},
]
lb_health_checks = [
{
protocol = "HTTP"
port = 8080
path = "/"
matcher = "200"
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
interval = 30
},
]
} Module itself: resource "aws_lb" "lb" {
# ...
load_balancer_type = "application"
}
resource "aws_lb_target_group" "lb_target_group" {
count = "${length(var.lb_listeners)}"
# ...
protocol = "${lookup(var.lb_listeners[count.index], "instance_protocol")}"
port = "${lookup(var.lb_listeners[count.index], "instance_port")}"
health_check = ["${var.lb_health_checks}"]
lifecycle {
create_before_destroy = true
}
}
resource "aws_lb_target_group_attachment" "lb_target_group_attachment" {
count = "${length(var.lb_listeners)}"
target_group_arn = "${element(aws_lb_target_group.lb_target_group.*.arn, count.index)}"
target_id = "${aws_instance.instance.id}"
}
resource "aws_lb_listener" "lb_listener" {
count = "${length(var.lb_listeners)}"
load_balancer_arn = "${aws_lb.lb.arn}"
protocol = "${lookup(var.lb_listeners[count.index], "lb_protocol")}"
port = "${lookup(var.lb_listeners[count.index], "lb_port")}"
ssl_policy = "${lookup(var.lb_listeners[count.index], "lb_protocol") == "HTTPS" ? "ELBSecurityPolicy-2016-08" : ""}"
certificate_arn = "${lookup(var.lb_listeners[count.index], "lb_protocol") == "HTTPS" ? lookup(var.lb_listeners[count.index], "ssl_certificate_id", "") : ""}"
default_action {
target_group_arn = "${element(aws_lb_target_group.lb_target_group.*.arn, count.index)}"
type = "forward"
}
} |
Actually it did worked for me without What I just told about that game?.. exactly, I almost felt the joy of finally getting my super simple task of adding an ELB to my module (a 2-day endeavor!) done, and boooom! In that specific case my workaround was to provide |
This is a major blocker for us. Related: hashicorp/terraform-provider-null#18 |
Hi all! This issue is covering the same root problem as #7034, and a solution for this has now been merged into master for inclusion in the forthcoming v0.12.0 release. This need was addressed by introducing a new The equivalent to that for the situation in this issue would be something like this: dynamic "listener" {
for_each = var.listener
content {
instance_port = each.value.instance_port
instance_protocol = each.value.instance_protocol
lb_port = each.value.lb_port
lb_protocol = each.value.lb_protocol
}
} |
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. |
Terraform Version
Terraform Configuration Files
Debug Output
Crash Output
None
Expected Behavior
The receiving module should receive the listener list intact. However, the above output seems to say that the list elements are being unset.
Actual Behavior
The receiving module does not appear to be receiving the list properly.
Steps to Reproduce
terraform init
terraform apply
Additional Context
Additionally, if the list in question is not passed with the data source element, but hardcoded in the receiving module, the list is intact.
The text was updated successfully, but these errors were encountered: