Rename terraform module name or resource name without recreating it

Lets say you want to rename your module after terraform is applied atleast once.

Example:

Lets say you have a module access

module "access" {
  source     = "..."
  variables  = "..."
}

and you want to rename it to iam like

module "iam" {
  source     = "..."
  variables  = "..."
}

Normal ways:

By destroying and recreating
terraform apply -destroy -target module.access
terraform apply -target=module.iam

Best way:

Using

terraform state mv module.access module.iam

Note: We can manually edit the state file and fix it. You can do that only when you have permission to the remote backend(if you are having one) and when you are expert in understanding the state file.

Comments

comments powered by Disqus