Hey all, I am trying to do some refactoring to move modules. Let’s call our huge module X, which has a resource file s3.tf. s3.tf is using a module to create a bucket so terraform plan will spit out the address as module.<module_name>.<s3_bucket_name>.aws_s3_bucket.bucket
.
I want to move this out of module X and create a separate module Y and have the same resource file but under Y
Below will be the new project structure
.
└── root/
├── X/
│ ├── main.tf
│ ├── variables.tf
│ ├── other tf files
│ └── s3.tf -- which will be deleted during the move
├── Y/
│ ├── s3.tf
│ ├── main.tf
│ └── other tf files
├── main.tf
└── output.tf
I am trying to use the moved
block to move the resources but Terraform is not able to find the correct movement of modules/resource. I have tried this in root/main.tf
moved {
from = module.X.module.<s3_bucket_name>.aws_s3_bucket.bucket
to = module.Y.module.<s3_bucket_name>.aws_s3_bucket.bucket
}
What am I missing? With the current plan, it will destroy the resources and recreate the resource with the same address.