vscode-terraform icon indicating copy to clipboard operation
vscode-terraform copied to clipboard

Rename a symbol within a module

Open radeksimko opened this issue 4 years ago • 7 comments

Use Cases

While working on a module of non-trivial size with many references users would benefit from having the ability to rename identifiers.

Specifically:

  • local value names
  • variable names
  • module (call) names
  • provider aliases
  • resource reference names
  • data sources reference names

Out of scope

Cross-module

Users would also indeed benefit from performing such renames across modules which reference each other - which specifically affects variable and outputs names, but we can ship renaming capability within a single module first - which can be still useful.

We can rely on terraform's strict validation mechanism which wouldn't allow the user to plan or apply a config where input is missing, or reference is referring to wrong name.

TODO: Create a separate issue

tfvars

TODO: Create a separate issue

Expected User Experience

Screenshot 2021-07-21 at 15 48 59

User can click Rename from the context menu in positions described below.

Local Values

Screenshot 2021-07-21 at 16 06 24 Screenshot 2021-07-21 at 16 06 09

Variables

Screenshot 2021-07-21 at 16 01 08 Screenshot 2021-07-21 at 16 01 18

Resources / Data Sources

Screenshot 2021-07-21 at 16 05 09 Screenshot 2021-07-21 at 16 04 48

Provider Aliases

Screenshot 2021-07-21 at 16 07 43 Screenshot 2021-07-21 at 16 08 08 Screenshot 2021-07-21 at 16 10 42

Module (Call) Reference Names

Screenshot 2021-07-21 at 16 15 34 Screenshot 2021-07-21 at 16 14 41

Proposal

TODO

Outstanding questions

  • Should/could we also (optionally) rename the name within state via terraform state mv?

radeksimko avatar Jul 21 '21 15:07 radeksimko

With the addition of the refactoring features in v1.1, I think it's worth considering whether renaming a resource should automatically generated a moved block adjacent to it, which would therefore record that the rename took place in a way that the next terraform apply can take into account automatically.

I would not generally suggest having the editor integrations implicitly run any actions that will create new state snapshots, because I think that blurs the line between developing a change and applying that change. It could perhaps be okay to allow a user to explicitly run a command like terraform state mv, but it could be pretty disruptive for it to happen automatically without any explicit direction in case someone else runs terraform apply on the unmodified configuration before the author's changes have been merged. (Terraform would propose to delete the object at the new address, because it doesn't appear to exist in the configuration from the perspective of the other collaborator.)

apparentlymart avatar Sep 12 '22 16:09 apparentlymart

How is this not a feature!?

DanCRichards avatar Aug 02 '23 01:08 DanCRichards

Is this being worked on or at least on the roadmap? It's something that is present in other IDE like Jetbrain's PHPStorm, so I am quite surprised it is still not supported on this VS Code extension.

+1 for this obviously

lucaspierru-convelio avatar Oct 04 '23 13:10 lucaspierru-convelio

Generating moved blocks from this would be an incredible feature for productivity! Refactoring in Terraform is a quite tedious effort, even with tools like tfautomv.

FalconerTC avatar Feb 13 '24 13:02 FalconerTC

Any progress on this issue?

vladc2s avatar Apr 04 '24 09:04 vladc2s