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

data source aws_route_tables returns list of strings #23480

Closed
yongzhang opened this issue Mar 3, 2022 · 7 comments
Closed

data source aws_route_tables returns list of strings #23480

yongzhang opened this issue Mar 3, 2022 · 7 comments
Labels
service/ec2 Issues and PRs that pertain to the ec2 service.

Comments

@yongzhang
Copy link

yongzhang commented Mar 3, 2022

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

Terraform CLI and Terraform AWS Provider Version

Terraform version: v1.1.7
AWS Provider version: 4.3.0

Affected Resource(s)

  • data source: aws_route_tables

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

data "aws_route_tables" "non_main" {
  vpc_id = data.aws_vpc.current.id

  filter {
    name   = "association.main"
    values = ["false"]
  }
}

resource "aws_route" "routes_to_devops" {
  for_each = var.environment != "devops" ? data.aws_route_tables.non_main.ids : []

  route_table_id         = each.value
  destination_cidr_block = var.vpc_cidr["devops"]
  transit_gateway_id     = data.aws_ec2_transit_gateway.parent.id

  depends_on = [aws_ec2_transit_gateway_route.route_to_vpc]
}

Debug Output

No.

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform apply
│ Error: Invalid for_each argument
│
│   on vpc.tf line 38, in resource "aws_route" "routes_to_devops":
│   38:   for_each = var.environment != "devops" ? data.aws_route_tables.non_main.ids : []
│     ├────────────────
│     │ data.aws_route_tables.non_main.ids is list of string with 6 elements
│     │ var.environment is "dev"
│
│ The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type list of string.
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/ec2 Issues and PRs that pertain to the ec2 service. labels Mar 3, 2022
@mattburgess
Copy link
Collaborator

As the error suggests, you need to provide a set, not a list to for_each. You can use the toset() function to do this as per https://www.terraform.io/language/functions/toset.

@yongzhang
Copy link
Author

As the error suggests, you need to provide a set, not a list to for_each. You can use the toset() function to do this as per https://www.terraform.io/language/functions/toset.

yes we could do this, but if we look into the docs, data.aws_route_tables.non_main.ids should return the set not list of strings, and I can confirm it works very well in version 3.74.x.

@justinretzolk
Copy link
Member

Hey @yongzhang 👋 The incorrect documentation was caught be another community member, and a PR has been merged to change set in the documentation to list (#23474). The documentation will be updated as soon as the next release goes out (a process that has actually already started at time of writing!).

Given that information, we'll close this one for now. If you feel we've done this in error, please do let us know.

@github-actions github-actions bot removed the needs-triage Waiting for first response or review from a maintainer. label Mar 4, 2022
@yongzhang
Copy link
Author

@justinretzolk I checked into the source code here: https://github.com/hashicorp/terraform-provider-aws/blob/v3.74.3/internal/service/ec2/route_tables_data_source.go#L29, in v3.74.x, it was TypeSet, so is it by intention to fallback to TypeList in v4.x?

@justinretzolk
Copy link
Member

Hey @yongzhang -- that's correct, this was an intentional change from TypeSet to TypeList that happened during the v4 upgrade. The CHANGELOG mentions for 4.0.0 mentioned this here:

data-source/aws_route_tables: The type of the ids attribute has changed from Set to List. If no route tables match the specified criteria an empty list is returned (previously an error was raised) (#21219)

@yongzhang
Copy link
Author

Hey @yongzhang -- that's correct, this was an intentional change from TypeSet to TypeList that happened during the v4 upgrade. The CHANGELOG mentions for 4.0.0 mentioned this here:

data-source/aws_route_tables: The type of the ids attribute has changed from Set to List. If no route tables match the specified criteria an empty list is returned (previously an error was raised) (#21219)

ahh, didn't notice this one, thanks

@github-actions
Copy link

github-actions bot commented May 9, 2022

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 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests

3 participants