Open
Description
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 anyvariable
withdefault
into alocals
entry