Skip to content
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

Allow data resource that lookup sets of items to return empty sets. #17540

Closed
bcsgh opened this issue Feb 10, 2021 · 7 comments · Fixed by #21219 or #22776
Closed

Allow data resource that lookup sets of items to return empty sets. #17540

bcsgh opened this issue Feb 10, 2021 · 7 comments · Fixed by #21219 or #22776
Assignees
Labels
bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS.
Milestone

Comments

@bcsgh
Copy link

bcsgh commented Feb 10, 2021

Community Note

  • Please vote on this issue by adding a � reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

data resource that exist to generate a list of items should (or should be able to) return an empty list when no resource match the filters used.

New or Affected Resource(s)

More or less any data resource ending in a plural, a few of many that likely exhibit this issue:

  • aws_autoscaling_groups
  • aws_instances
  • aws_subnet_ids
  • ...

Potential Terraform Configuration

I need to create a resource for_each of some other thing. Things that exists outside TF's control.

data "aws_things" "lookup" {
  ...
}

resource "aws_other_thing" "make" {
  for_each = data.aws_things.lookup.ids

  ...
  build_from_thing = each.key
}

(note this is only one of several patterns that run into this problem, but in my experience the most common.)

Right now this works, but only when something is actually found.
When the possibility exist that in, non error condition, there may be zero of those things, making things work is much more complex.
All (or most) data resource that lookup sets of things issue an error when they find nothing.

Attempted Solutions

The general workaround is to use a wider query that is assured to always return something and lookup enough about each of those results to manually filter that in terraform.
Besides being much more complex and requiring many more data requests, this has many other issues that I shouldn't need to go into.

References

hashicorp/terraform#27712

@bcsgh bcsgh added the enhancement Requests to existing resources that expand the functionality or scope. label Feb 10, 2021
@ghost ghost added service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service. labels Feb 10, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 10, 2021
@ewbankkit ewbankkit added proposal Proposes new design or functionality. and removed needs-triage Waiting for first response or review from a maintainer. service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service. labels Feb 10, 2021
@bcsgh
Copy link
Author

bcsgh commented Feb 11, 2021

Glad to see that. It looks like other more specific issues predate this one. I'll leave it up to you to decide if having a totally general issues open is worth while. If not I'm find with this being marked as a duplicate.

Keep up the good work!

p.s. could someone please acknowledge hashicorp/terraform#13022 ?

@bflad
Copy link
Contributor

bflad commented Feb 11, 2021

We have now documented in our Provider Design documentation that plural data sources should return zero, one, or multiple results without error. Singular data sources should still return an error when the remote component is not found.

We can go back through any non-conformant plural data sources to fix them up, but this might want to wait until our next major release since it is a behavior change for the existing cases. I'm going to mark it with that milestone for tracking for now, but it might be done sooner depending on some further investigation work to determine if it was previously possible to rely on the error in configurations (e.g. with try()).

p.s. could someone please acknowledge hashicorp/terraform#13022 ?

The maintainers for this project are separate. We cannot influence any prioritization efforts upstream. The product manager for Terraform CLI is fairly open to meeting with folks to discuss things, so that is a potential option there.

@bflad bflad added bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS. and removed enhancement Requests to existing resources that expand the functionality or scope. proposal Proposes new design or functionality. labels Feb 11, 2021
@bflad bflad added this to the v4.0.0 milestone Feb 11, 2021
@zpriddy
Copy link

zpriddy commented Jun 3, 2021

I was wondering if there are any updates on this or #13951 ?

@anGie44
Copy link
Contributor

anGie44 commented Jan 20, 2022

List of Affected Data Sources:

@github-actions
Copy link

This functionality has been released in v4.0.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS.
Projects
None yet
5 participants