Support naming convention auto-fix
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
}`,
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.
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.
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.
I would like this feature too. It seems there are similar tools like: https://github.com/suzuki-shunsuke/tfmv