I currently have a project that has grown quite a bit and I wonder if it is possible to break it down into small elements without the need to destroy everything that has been deployed in the cloud, I have worked with modules for lambda, event bridge, api gateway for example.
Thanks.
CodePudding user response:
Youcef's answer above is accurate, however it's also a bit outdated depending on your terraform version.
HashiCorp introduced the moved block configuration in one of the last few releases to help with this exact issue. Here's a link to a step-by-step guide on what this process is like:
It looks like this:
moved {
from = module.security_group.aws_security_group.sg_8080
to = module.web_security_group.aws_security_group.this[0]
}
CodePudding user response:
Yes, you can by moving resources in the terraform.tfstate
, it is really complicated but not impossible.
To do so, you need to:
- list your resources in your actual project, using for example
terraform state list
- create another project(s), based on your logic
- each project should have a tfstate
- now you can move resources using for example:
terraform state mv -state-out=../child/terraform.tfstate module.xxxx module.xxx
- move the script of your resources from the parent to child project
- then plan & apply your projects
Maybe I forgot some steps, but these are the big lines to solve your problem(I guess).