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: Move a block between modules #1566

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

New Code Action: Move a block between modules #1566

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

Comments

@radeksimko
Copy link
Member

radeksimko commented Jan 5, 2024

Background

As Terraform adoption grows, users may begin with a single root module and end up with a lot of code which then needs refactoring in the sense of breaking it down to different modules.

This is usually mostly done by manually copying and pasting blocks around and adding moved {} blocks where existing state is involved. Such process can be laborious and the server could make it easier.

For example, the user may start with ./main.tf

resource "aws_vpc" "main" {
  // ...
}

resource "aws_instance" "jumphost" {
  // ...
}

and expects to end up with a new module/folder in ./network

and ./network/main.tf

resource "aws_instance" "jumphost" {
  // ...
}

and a modified ./main.tf

resource "aws_instance" "jumphost" {
  // ...
}

module "network" {
  source = "./network"
}

moved {
  from = aws_vpc.main
  to   = module.network.aws_vpc.main
}

Proposal

  • Provide code actions:
    • Move a resource to an existing module
    • Move a data to an existing module
    • Move a resource to a new module
    • Move a data to a new module

The moved block could be optional and maybe have sensible default either to generate it, or base it on whether there is a backend block and/or existing state.

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