Terraform: create resources based on exported resource files

Hi,
Sorry, I'm new to CX as Code and Terraform and I'm reading a lot of documents and videos on this topic. My main goal is to import an architect flow and its dependencies (e.g. data action) and create this flow and dependencies in another Gen Cloud org.
At this moment, I was able to:

  • Get the flow via Archy and save it to a YAML file
  • Get the flow resource and all their dependencies (e.g. data actions) via Terraform:
    resource "genesyscloud_tf_export" "export_flow" {
    directory = "./genesyscloud/flow"
    export_as_hcl = true
    log_permission_errors = true
    include_state_file = true
    enable_dependency_resolution = true
    split_files_by_resource = true
    include_filter_resources = ["genesyscloud_flow::Name of architect flow"]
    }
    This export generated several TF files in the "genesyscloud/flow" folder containing the flow and dependent resources.

However, I'm stuck at this point:
How to take all this information and create these resources in another Genesys Cloud Organization?

I know I could insert resource by resource into the main.tf file and then create them in the new environment, but would there be a way to create these resources from the resource files in the “flow” folder?

I would appreciate any suggestions.

Thanks in advanced.
Julio Masuda

Hi @Julio_Masuda

Before you export, make sure that the field include_state_file is set to false , this is to prevent the exported config doesn't contain any GUIDs that are specific to that org. Then all you have to do is to cd into the export folder, swap the OAuth credentials for the new target org and run terraform init and apply for the contents that got exported.

Hi @Kavin_Bala ,
I finally understood what you suggested and it worked correctly.
Thank you very much !
I would just like to let other people interested in this topic know what I did:
Export the resources to local folder

  1. Get the flow via Archy and save it to a YAML file
  2. Get the flow resource and all their dependencies (e.g. data actions) via Terraform:
    resource "genesyscloud_tf_export" "export_flow" {
    directory = "./genesyscloud/flow"
    export_as_hcl = true
    log_permission_errors = true
    include_state_file = false
    enable_dependency_resolution = true
    split_files_by_resource = false
    include_filter_resources = ["genesyscloud_flow::Name of architect flow"]
    }
    This export generated in the "genesyscloud/flow" folder:
  • "scripts" subfolder
  • genesyscloud.tf
  • terraform.tfvars

Import resources to another organiztion

  1. created a new folder
  2. copied into this folder:
  • "scripts" subfolder
  • genesyscloud.tf
  • terraform.tfvars
  1. I changed the credentials data in the genesyscloud.tf file to another organization's credentials.
  2. Executed:
    terraform.exe init
    terraform.exe plan
  3. This last command will generate some error messages and you will have to edit genesyscloud.tf to fix the reported problems.
  4. Finally I executed:
    terraform.exe apply

Sorry, I haven't exported the yaml flow to the other organization yet. I'll still work on that.

Best regards,
Julio Masuda

1 Like

Just complementing the previous post, I was also able to create the flow via Terraform in the other organization:

  1. Copy the yaml file to new folder
  2. Edit genesyscloud.tf file:
    resource "genesyscloud_flow" "INBOUNDCALL_Architect_flow" {
    depends_on = [genesyscloud_routing_queue.someQueue, genesyscloud_integration_action.someAction]
    file_content_hash = filesha256("${path.module}/architect_flow.yaml")
    filepath = "${path.module}/architect_flow.yaml"
    }
  3. Execute:
    terraform.exe plan
    terraform.exe apply

Best regards,
Julio Masuda

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