Home > Blockchain >  Terraform split the monolith
Terraform split the monolith

Time:11-05

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:

https://developer.hashicorp.com/terraform/tutorials/configuration-language/move-config#move-your-resources-with-the-moved-configuration-block

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:

  1. list your resources in your actual project, using for example terraform state list
  2. create another project(s), based on your logic
  3. each project should have a tfstate
  4. now you can move resources using for example: terraform state mv -state-out=../child/terraform.tfstate module.xxxx module.xxx
  5. move the script of your resources from the parent to child project
  6. then plan & apply your projects

Maybe I forgot some steps, but these are the big lines to solve your problem(I guess).

  • Related