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

Support naming convention auto-fix #227

Open
Fraser-Isbester opened this issue Dec 10, 2024 · 3 comments
Open

Support naming convention auto-fix #227

Fraser-Isbester opened this issue Dec 10, 2024 · 3 comments

Comments

@Fraser-Isbester
Copy link

Fraser-Isbester commented Dec 10, 2024

The introduction of moved blocks means that we can now statically rename resources.

Here is an example test case of what I'm proposing.

Name: "mixed_snake_case: kebab-case to snake_case",
Content: `
resource "aws_instance" "my-instance" {}`,

Expected: `
resource "aws_instance" "my_instance" {}
# Auto-generated by tflint. Safe to remove after apply.
# https://developer.hashicorp.com/terraform/language/moved
moved {
  from = aws_instance.my-instance
  to = aws_instance.my_instance
}`,

WIP PR

@bendrucker
Copy link
Member

Clever!

If we are going to rename resources I'd say updating all expressions that reference them is essential. Generating moved blocks is more of a bonus.

Also, I'm thinking moved block generation should be off by default. Ideally your linter runs before any state is modified. But it certainly makes sense to offer it as a configurable option when migrating a project with existing state.

@Fraser-Isbester
Copy link
Author

Yeah, agreed to both! I will look into updating all references, is there a tflint native mechanism for this? I only saw mechanisms for updating code at the specific lint location.

@bendrucker
Copy link
Member

is there a tflint native mechanism for this?

Yeah I believe auto-fix has just been focused on the range of the issue. Updating references might require a bit of re-thinking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants