Migrating resources between organizations using terraform

Hello,

want to ask/confirm if following idea is correct for migrating resources between organizations that was not previously managed using terraform:

what I want to achieve is to migrate some resources from development organization into production organization (some resources is already present in both orgs but not all of them - that's why tfstate file is needed)

In last step I will have configuration files "*.tf" from development and "terraform.tfstate" from production so from my understanding all resources from development org should be migrated into production and as we have "terraform.tfstate" from production all resources which is in development and it's also present in production should be properly mapped using ID from production ?

Is this the right way to do it or shouldn't it be done this way?

Hi @sieni_kam
Excluding the state file from the dev org is right because that generates a configuration that can be applied to a different org.
When exporting to another org, generally it works best if the destination is a new org, because the application will fail on resources in the destination org with the same name. Terraform will try to create, but not update.
I'm not sure if having a tfstate file in the prod org export has any effect on this issue, so I'm going to route this to the CX as Code team for a second opinion.

Source: https://developer.genesys.cloud/devapps/cx-as-code/faq#how-to-get-started-with-existing-already-configured-genesys-cloud-organizations--is-it-the-best-way-to-export-your-production-org-objects-and-then-start-applying-them-on-each-org-to-make-sure-the-environments-are-consistent-and-then-use-the-exported-files-as-baseline-under-source-control-and-update-them-and-apply-them-through-the-path-to-production-in-your-pipelines-

Hello @jacobshaw

any news on this topic ? (also I have updated diagram for better understanding)

Hi @sieni_kam
Sorry for the delay! This one fell off my radar. I brought this up to the team again, so I'll keep you posted.

Hi @sieni_kam,

A few things to consider:

  1. You will need to set include_state_file=true otherwise the object ids will not be exported as general objects in CX as Code.

  2. The tfstate file is a private API to terraform. So you do not want to use your TFSTATE file (e.g. your backing state file) from production against your Dev environment.

  3. If I am understanding your question, you want to bring development org in sync with your product org.

    a. Export your DEV or and keep your terraform.tfstate files AND your object definitions.
    b. Export your production org and then throw out the TFState. Just keep the exported objects defined as HCL.
    c. Take your generated TF files (which contain the actual object definitions in an HCL format) and do a
    terraform plan using those files against your development environment. This will tell you what is going to
    change.
    d, Apply your generated TF files from the prod org. Most (not all) objects will fail to create if there is already an object out there with the same name as the object being created.

Trying to sync environments that are not under Terraform management is a bit if a slog. That why I always put to lock down environments and only allow changes going in one environment (dev) for anything being managed by Terraform/CX as Code.

I hope that helps. If this becomes really messy or you do not feel comfortable doing this work, I would recommend a PS engagement as we have people in the PS group who have done migrations and getting environments in sync and are very well-versed in how to do this

Thanks,
John Carnell
Director, Developer Engagement

1 Like

Hello , is there any demo video for the migration process.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.