Skip to content

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

Open
@radeksimko

Description

@radeksimko

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions