-
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
provider/aws Add support for aws_subnet_ids as a data source #13188
provider/aws Add support for aws_subnet_ids as a data source #13188
Conversation
Hi @cwood! Thanks for working on this. We didn't initially implement these "plural" data sources because Terraform's core currently makes it hard to wrangle lists of complex objects like this. This is why, for example, the I certainly agree that being able to list subnets matching constraints would be useful, but I'm not sure that this particular design would be very usable with today's language limitations. For example, there isn't a good way to express "all of the id attribute values from the members of this list" in the interpolation language. Perhaps in the short term it'd be useful to have an data "aws_subnet_ids" "example" {
vpc_id = "${var.vpc_id}"
}
data "aws_subnet" "example" {
count = "${length(data.aws_subnet_ids.example.ids)}"
id = "${aws_subnet_ids.example.ids[count.index]}"
}
output "subnet_cidr_blocks" {
value = ["${data.aws_subnet.example.*.cidr_block}"]
} What do you think? |
That's honestly fine with me. I only want subnet_ids anyway and to use a vpc_id |
++1 -- Thanks for considering this. The lack of either aws_subnets or aws_subnet_ids is causing a lot of code bloat for me. |
Thanks for the update @cwood. Looking good now! The only other thing (which I'm sorry I didn't catch on the first pass) is that we should probably have an acceptance test for this. Acceptance tests for data sources can be kinda weird, but I think we could get away here with something that applies a config that creates a VPC and a couple subnets and then uses your data source to retrieve the subnets from that VPC and verifies that it gets back the two subnet ids we expect. (It looks like Travis caught some compile-time issues, too...) |
I am working on the compiling issues right now. Ill work on an acceptance test later. Is there a way I can run only the acceptance test for this data source and not the whole collection. |
There's some long details on this here: ...but in summary: you can use the |
42262b0
to
4215b25
Compare
cc78f0b
to
e41e262
Compare
e41e262
to
d7a319f
Compare
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. |
Fixes #9843