-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
conditional in module output #12475
Comments
Seems due to hashicorp/hil#50 |
Terraform version: 0.8.8 I think have a similar case:
JSON files for reference:
s3-deployment-ro.json.tpl
Error after invoking
Documentation is not specific on which role argument for Hope that helps on debugging it. Cheers! EDIT2:
|
@gstlt try changing it to |
@PurrBiscuit Tried with an But when putting JSON file inline (like below) it suddenly works perfectly. I'm guessing rendering is screwing up with JSON syntax somehow....
Note: Terraform version 0.8.8 |
A solution: Since the policy is not a "real" template, I could (or should) use
EDIT: I'd say it's not the same issue after all, but will leave comments for a reference :) Sorry for spamming. |
Hi all! Sorry things aren't working as expected here. This looks like the same issue as #11566, with a dash of #9080. Since we already have an issue tracking this, I'm going to close this one to consolidate discussion over there. Note that there is a workaround document in the comments there, of using the splat syntax to refer to the zero or one resources in a conditional set. Thanks for reporting this! |
To save you some clicking, here is an example work around if count is always either zero or 1:
|
This is my workaround. I hope it helps someone. resource "aws_subnet" "public_a" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.0.0.0/24"
availability_zone = "eu-west-1a"
tags {
Name = "Public Subnet A"
}
}
# ... b, c
resource "aws_subnet" "private_a" {
count = "${var.create_private_subnet == true ? 1 : 0}"
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.0.100.0/24"
availability_zone = "eu-west-1a"
tags {
Name = "Private Subnet A"
}
}
# ... b, c
output "database_subnet_ids" {
value = [
"${coalesce(join("", aws_subnet.private_a.*.id), join("", aws_subnet.public_a.*.id))}",
"${coalesce(join("", aws_subnet.private_b.*.id), join("", aws_subnet.public_b.*.id))}",
"${coalesce(join("", aws_subnet.private_c.*.id), join("", aws_subnet.public_c.*.id))}"
]
} |
EDIT: Nah after further testing, it's not working too good. Ternary operator works for me. My use case is a bit ugly though ;) Terraform version output "connection_ips_ceph" {
value = "${var.count_ceph != 0 ? "\n ssh ${var.login_user}@${join("\n ssh ${var.login_user}@", openstack_networking_floatingip_v2.fip_ceph.*.address)}" : ""}"
} |
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. |
Having trouble setting conditionals in a module's output to ignore resource output interpolation if the resource isn't being created due to a
count
conditional.Terraform Version
0.8.7
Affected Resource(s)
all resources but in this case specifically trying to work with
Terraform Configuration Files
Expected Behavior
Ignore the resource attribute outputs in the
output
resources if those resources aren't being created in a region. Right now we only want ourus-east-1
terraform state to manage out IAM roles in AWS (since they are global per account.) The conditional in theoutput
resource is still trying to evaluate theaws_iam_instance_profile.profile.name
resource output even when the region iseu-central-1
.Actual Behavior
Since terraform isn't creating these resources in that region, due to the
count
conditional being used on them it's failing terraform plans in that region with:Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform plan
The text was updated successfully, but these errors were encountered: