Genesys Cloud - Developer Community!

 View Only

Sign Up

Export person from Dev Environment and create the same person in Prod Environment with all the dependency using cx as code.

  • 1.  Export person from Dev Environment and create the same person in Prod Environment with all the dependency using cx as code.

    Posted 05-13-2025 03:31

    I am trying to export user from Dev and then trying to create a user in Production with its dependency. so, when i export the user from Dev using cx as code it create.tf file in that file it define all the dependency of user but when it try to use that .tf file to create user in Prod with its dependency but if dependency like skill already exist in that case process stop and thrown an error. How to handle the .tf file so that it checks if the dependency already exists, it uses the existing one, but if the dependency doesn't exist, in that case it should create the dependency.

     Export User from Source.
    As we define our folder structure as below, and suppose we are treating test_Org as the source.
    /cxascode
    /Test_Org
    ├── main.tf
    ├── variables.tf
    ├── terraform.tfvars
    /Prod_Org
    ├── main.tf
    ├── variables.tf
    ├── terraform.tfvars
     
    main.tf in test org is below
    terraform {
    required_providers {
    genesyscloud = {
    source = "mypurecloud/genesyscloud"
    version = "~> 1.10"
    }
    }
    }
     
    provider "genesyscloud" {
    oauthclient_id = var.client_id
    oauthclient_secret = var.client_secret
    aws_region = var.region
    }
     
    resource "genesyscloud_tf_export" "include-filter" {
    directory = "./genesyscloud/include-filter"
    export_format = "hcl"
    log_permission_errors = true
    include_filter_resources = ["genesyscloud_user::^shalini\\.agarwal@clarisys\\.com$"]
    enable_dependency_resolution = true
    }
    Run below from your project Source folder:
    terraform init
    terraform plan
    terraform apply
     
     
    This creates .tf files in .\genesyscloud\include-filter
     
    Steps to perform in the Dest env
    Migrate the User to the destination.
    Prepare main.tf as below
    provider "genesyscloud"
    {
    oauthclient_id = var.client_id
    oauthclient_secret = var.client_secret
    aws_region = var.region
    }
     
    Copy the exported .tf files from .\genesyscloud\include-filter from the source directory and paste them into the Destination directory of the project.
    Now the destination directory will look like
    /cxascode
    /Test_Org
    ├── main.tf
    ├── variables.tf
    ├── terraform.tfvars
    /Prod_Org
    ├── main.tf
    ├── genesyscloud.tf
    ├── variables.tf
    ├── terraform.tfvars
     
     
    Run It from your project Destination folder:
    terraform init
    terraform plan
    terraform apply
     
    Here is the genesyscloud.tf file
    terraform {
    required_providers {
    genesyscloud = {
    source = "registry.terraform.io/mypurecloud/genesyscloud"
    version = "1.62.0"
    }
    }
    }
     
    resource "genesyscloud_auth_division" "Home" {
    description = "description"
    home = true
    name = "Home"
    }
     
    resource "genesyscloud_routing_skill" "Americas" {
    name = "Americas"
    }
     
    resource "genesyscloud_routing_skill" "Chat_Skill" {
    name = "Chat_Skill"
    }
     
    resource "genesyscloud_routing_skill" "Email_Skill" {
    name = "Email_Skill"
    }
     
    resource "genesyscloud_routing_skill" "Inbound_Voice_Skill" {
    name = "Inbound_Voice_Skill"
    }
     
    resource "genesyscloud_routing_skill" "SMS_Skill" {
    name = "SMS_Skill"
    }
     
    resource "genesyscloud_routing_skill" "Standard_Skill" {
    name = "Standard_Skill"
    }
     
    resource "genesyscloud_routing_skill" "Web_Messaging_Skill" {
    name = "Web_Messaging_Skill"
    }
     
    resource "genesyscloud_routing_skill" "WhatsApp" {
    name = "WhatsApp"
    }
     
    resource "genesyscloud_routing_skill" "voice_skil" {
    name = "voice_skil"
    }
     
    resource "genesyscloud_user" "shalini_agarwal_clarisys_com" {
    division_id = "${genesyscloud_auth_division.Home.id}"
    email = "shalini.agarwaltest001@clarisys.com"
    name = "shalini_agarwal_clarisys_com"
    state = "active"
    voicemail_userpolicies {
    alert_timeout_seconds = 10
    send_email_notifications = true
    }
    acd_auto_answer = false
    addresses {
    phone_numbers {
    extension = "2004"
    media_type = "PHONE"
    type = "WORK2"
    }
    }
    department = "Development"
    routing_languages = []
    routing_skills {
    skill_id = "${genesyscloud_routing_skill.Inbound_Voice_Skill.id}"
    proficiency = 0
    }
    routing_skills {
    proficiency = 0
    skill_id = "${genesyscloud_routing_skill.Email_Skill.id}"
    }
    routing_skills {
    proficiency = 0
    skill_id = "${genesyscloud_routing_skill.SMS_Skill.id}"
    }
    routing_skills {
    proficiency = 0
    skill_id = "${genesyscloud_routing_skill.voice_skil.id}"
    }
    routing_skills {
    proficiency = 0
    skill_id = "${genesyscloud_routing_skill.Web_Messaging_Skill.id}"
    }
    routing_skills {
    proficiency = 0
    skill_id = "${genesyscloud_routing_skill.Chat_Skill.id}"
    }
    routing_skills {
    proficiency = 0
    skill_id = "${genesyscloud_routing_skill.Americas.id}"
    }
    routing_skills {
    proficiency = 0
    skill_id = "${genesyscloud_routing_skill.WhatsApp.id}"
    }
    routing_skills {
    proficiency = 5
    skill_id = "${genesyscloud_routing_skill.Standard_Skill.id}"
    }
    }
     
     
    Help me to manage this

    #CXasCode

    ------------------------------
    Hari Shankar
    Genesys Specialist
    ------------------------------