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

Support resource-scope locals #31737

Open
schollii opened this issue Sep 5, 2022 · 1 comment
Open

Support resource-scope locals #31737

schollii opened this issue Sep 5, 2022 · 1 comment
Labels
enhancement new new issue not yet triaged

Comments

@schollii
Copy link

schollii commented Sep 5, 2022

Terraform Version

1.3 beta1

Use Cases

Especially when using a map or list of resources, it can be useful to create an expression based on the each object. If this expression is used in more than one place, there can be a significant amount of duplication of code, OR you have to define a local write a local.

Attempted Solutions

variable "map" {
  type = map(number)
}

locals {
  ABC = { for k, v in var.map: k => something(v) }
}

resource aws_something "something" {
  for_each = var.map
  attribute = expression(local.ABC[each.value])
}

Proposal

variable "map" {
  type = map(number)
}

resource aws_something "something" {
  for_each = var.map
  self_locals {
     ABC = something(each.value)
  }
  attribute = expression(self_local.ABC)
}

References

No response

@schollii schollii added enhancement new new issue not yet triaged labels Sep 5, 2022
@crw
Copy link
Collaborator

crw commented Sep 8, 2022

Thanks for the feature request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants