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 local value as a variable #1570

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

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

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

Comments

@radeksimko
Copy link
Member

radeksimko commented Jan 5, 2024

Background

While refactoring Terraform configuration, users may sometimes leverage local values to extract some computations and make parts of the configuration "dynamic". There are even apparently tools which generate locals entries according to some reports:

The common theme of ending up in a situation where local value is used as a variable is most likely just misunderstanding of the language features. We cannot naturally change external tooling but the server could make it easier to fix these mistakes in existing configuration.

For example, the user may begin with

locals {
  instance_size = "t3.micro"
}

and end with

variable "instance_size" {
  type    = string
  default = "t3.micro"
}

Importantly we cannot tell whether a local variable was meant to be a variable as we don't have any context to decide or even guess that, we can give user the choice still though.

Proposal

  • Provide refactor.rewrite code action which turns existing local value into a variable
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