-
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
Sort AMI and snapshot IDs #13866
Sort AMI and snapshot IDs #13866
Conversation
I wanted to write an acceptance test for this, but I'm not quite sure how to go about it without relying on some hardcoded set of AMIs and EBS snapshots. |
Hi @joshuaspence! Testing of data sources is often a little tricky as you say, since we need to arrange for there to be data to test with. In many cases we use the corresponding managed resource as part of the test config to give us something to read and ensure it gets destroyed afterwards. Perhaps you could use tagging here with a random number value to create an isolated set of resources to query for? |
This doesn't quite work yet, I'm trying to figure out why.
|
I'm having some issues with adding test cases here and I think it's due to needing to use
|
Ready for review!
|
As a follow up to #13844, this pull request sorts the AMIs and snapshots returned from the `aws_ami_ids` and `aws_ebs_snapshot_ids` data sources, respectively. Basically the idea is that by sorting the IDs, the `aws_ami_ids` and `aws_ebs_snapshot_ids` data sources can be used similarly to the `aws_ami` and `aws_ebs_snapshot` data sources as if the `most_recent` attribute were set to `true`. For example: ```hcl data "aws_ami_ids" "main" # filter { ... } } output "ami_id" { value = "${length(data.ami_ids.main.ids) > 0 ? data.ami_ids.main.ids[0] : ""}" } ```
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. |
As a follow up to #13844, this pull request sorts the AMIs and snapshots returned from the
aws_ami_ids
andaws_ebs_snapshot_ids
data sources, respectively. Basically the idea is that by sorting the IDs, theaws_ami_ids
andaws_ebs_snapshot_ids
data sourcescan be used similarly to theaws_ami
andaws_ebs_snapshot
data source as if themost_recent
attribute were set totrue
. For example: