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

Report on mutually-exclusive count and for_each attributes #1587

Open
1 task
dbanck opened this issue Jan 18, 2024 · 0 comments
Open
1 task

Report on mutually-exclusive count and for_each attributes #1587

dbanck opened this issue Jan 18, 2024 · 0 comments

Comments

@dbanck
Copy link
Member

dbanck commented Jan 18, 2024

Context

While it's possible to declare count and for_each in a resource (and other) block, the configuration is not valid. We can catch this early in the enhanced validation.

resource "aws_instance" "name" {
  for_each = {
    "key" = "value"
  }
  count = 3
}

Trying to run the above configuration does not work. terraform validate will report this as an error:

╷
│ Error: Invalid combination of "count" and "for_each"
│ 
│   on main.tf line 25, in resource "aws_instance" "name":
│   25:   for_each = {
│ 
│ The "count" and "for_each" meta-arguments are mutually-exclusive, only one should be used to be explicit about the number of resources to be created.
╵

Proposal

  • Add a new validator in terraform-ls that checks if both attributes are present and raises a diagnostic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants