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

New Code Action: Rewrite variable as a local value #1569

Open
1 task
radeksimko opened this issue Jan 5, 2024 · 0 comments
Open
1 task

New Code Action: Rewrite variable as a local value #1569

radeksimko opened this issue Jan 5, 2024 · 0 comments
Labels

Comments

@radeksimko
Copy link
Member

radeksimko commented Jan 5, 2024

Background

While making Terraform configuration dynamic, users may sometimes leverage variable in a context where it's not appropriate, such as when the variable will never be provided from the outside (either as module input or by user).

Typically the user would encode the values in default, e.g.

variable "internal_name" {
  type    = string
  default = "foobar"
}

This may most likely be a result of them not knowing about or how to use local values, i.e. not knowing the same goal can be achieved more elegantly with

locals {
  internal_name = "foobar"
}

We may not always know the context to be able to reliably tell when a local value is more appropriate than a variable, therefore we cannot report this as a diagnostic.

We can however make it easier for the user to turn existing variables with defaults into local values.

Proposal

  • Provide refactor.rewrite code action which turns any variable with default into a locals entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant