-
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: Allow filtering of aws_subnet_ids by tags #13937
Conversation
This is the minimal amount of work needed to be able to create a list of a subset of subnet IDs in a VPC, allowing people to loop through them easily when creating EC2 instances or provide a list straight to an ELB.
I'm not a fan of the duplicated resources in the acceptance test and asked a question about that on gitter (it happens in a lot of other places but not all of them, for example the singular subnet data source does it like this for ip6 but not for ip4 tests) but when I tried removing the config without data sources step it failed and I don't know why with my limited exposure to the test framework. Could anyone explain why it's needed? |
Hey @tomelliff, thanks for the contribution! Data sources need to be evaluated after the actual resources are created. Usually this isn't a concern, as the data source configuration contains interpolated values from the actual resource creation, so Terraform graphs the resources accordingly. However, there are cases, like this one for example, where the data source isn't configured with interpolations on the dependent resource. This can sometimes be solved via adding |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Ah fair enough, hadn't spotted that somehow. Thanks for that! |
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. |
This is the minimal amount of work needed to be able to create a list of a subset of subnet IDs in a VPC, allowing people to loop through them easily when creating EC2 instances or provide a list straight to an ELB.
As mentioned in the docs updated this allows for configuration like this:
Which in my brief testing led to plans of the following:
The order appears to be stable every time I plan but to be honest I'm not sure exactly what the ordering is that's coming back from AWS' API. As long as it's stable I don't actually care what order my instances are placed in the subnets although I imagine that some people may have a requirement that different filters lead to a stable order of AZs but I've deliberately left that out of scope for now.
I've also just added filtering by tags but any of the filters on the singular subnet data source should be usable. I can add these if people want them or we can do that in a future PR if people want that functionality at a later date.
Testing looping through multiple times and also that sort order is stable:
Acceptance tests: