Legacy Dev Forum Posts

 View Only

Sign Up

Cx as Code with TypeScript and CDK

  • 1.  Cx as Code with TypeScript and CDK

    Posted 06-05-2025 19:34

    MiquelTrillaRomero | 2023-01-12 14:31:28 UTC | #1

    Hi all,

    I'm trying to use CX as Code with CDK for Terraform and typescript but it is not generating the output with the resources.

    I've tested with other providers (aws) and I can generate the resources without any issue, also I have generated the resources for Genesys when not using CDK.

    Anyone is using the same setup and is achiving a successful execution?

    Does anyone know if there is any limitation with the genesys provider?

    Thank you


    John_Carnell | 2023-01-12 19:01:54 UTC | #2

    Hi Miquel,

    Could you be more specific? Are you having problems executing CX as Code with the CDK. I know when it first came out we were trying it out and had no problems with it. Are you getting any kind of errors that might help provide guidance?

    Thanks, John Carnell Manager, Developer Engagement


    MiquelTrillaRomero | 2023-01-13 10:02:43 UTC | #3

    Hi John,

    What I've tested is the following code:

    // Copyright (c) HashiCorp, Inc // SPDX-License-Identifier: MPL-2.0 import { Construct } from "constructs"; import { App, TerraformStack } from "cdktf"; import { TfExport} from "./.gen/providers/genesyscloud/tf-export"; import { GenesyscloudProvider} from "./.gen/providers/genesyscloud/provider";

    class MyStack extends TerraformStack { constructor(scope: Construct, id: string) { super(scope, id); // define resources here new GenesyscloudProvider(scope,'Provider',{ awsRegion: 'XXXXX', oauthclientId: 'XXXXXXX', oauthclientSecret: 'XXXXXXX' }); new TfExport(scope,'Export',{ exportAsHcl: true, includeStateFile: true, directory: './fullExport' }); } }

    const app = new App(); new MyStack(app, "genesys-cx-as-code"); app.synth();

    What I get is the following terraform.tfstate file:

    { "version": 3, "serial": 1, "lineage": "9a206d32-095c-438d-86e3-607791f8e167", "backend": { "type": "local", "config": { "path": "/XXXXXX/terraform.genesys-cx-as-code.tfstate", "workspacedir": null }, "hash": 1721479173 }, "modules": [ { "path": [ "root" ], "outputs": {}, "resources": {}, "dependson": [] } ] }

    If instead of using CDK I execute the following main.tf:

    terraform { required_providers { genesyscloud = { source = "mypurecloud/genesyscloud" version = "~> 1.0.0" } }

    } resource "genesyscloudtfexport" "export" { directory = "./genesyscloud" includestatefile = true } provider "genesyscloud" { oauthclientid = "XXXXXXXX" oauthclientsecret = "XXXXXXXXX" aws_region = "XXXXXX" }

    Then what I get is this tfstate file:

    { "version": 4, "terraformversion": "1.3.7", "serial": 4, "lineage": "cfc976a9-fda0-24f9-c081-a08ab8386421", "outputs": {}, "resources": [ { "mode": "managed", "type": "genesyscloudtfexport", "name": "export", "provider": "provider[\"registry.terraform.io/mypurecloud/genesyscloud\"]", "instances": [ { "schemaversion": 0, "attributes": { "directory": "./genesyscloud", "excludeattributes": null, "id": "genesyscloud/genesyscloud.tf.json", "includestatefile": true, "resourcetypes": null }, "sensitiveattributes": [], "private": "bnVsbA==" } ] } ], "checkresults": null }

    So this time resources are correctly produced.

    I get no error on console or terminal, it just produce the files so I have no clue why when generating using the cdk resources are not produced.

    Any clue?


    John_Carnell | 2023-01-13 20:40:51 UTC | #4

    Hi Miguel,

    Thanks for posting this. I am going to play around with this either over the weekend or on Tuesday. Our Genesys Cloud offices are closed in the US for the Martin Luther King holiday.

    We have only played around with the CDK briefly and I used it to create some queues. I have never tried the export functionality with it, so it will be interesting to see what I can do with it.

    Just out of curiosity were any actual resources exported in the non-TF state module.

    Thanks for posting and I hope to have something for you next week.

    Thanks, John Carnell Manager. Developer Engagement


    MiquelTrillaRomero | 2023-01-16 10:38:16 UTC | #5

    Hi John,

    Probably I'm doing something wrong but I cannot generate anything, even a queue. Can you share a basic project that just create a queue so I can test on my end?

    This are the versions I'm using:

    Node: 16.13.0 cdktf: 0.14.3 go: 1.19.5 terraform: 1.3.7 genesys cloud provider: 1.10.0 O.S.: MacOS 13.1

    Thank you


    John_Carnell | 2023-01-17 18:24:51 UTC | #6

    Hi Miguel,

    Thanks for providing the information. So here is what I have been able to do today.

    1. I was able to re-install my environment. So I am running with Node v18.0.0.
    2. I was able to install the CDKTF (latest version) running Terraform v1.3.0.
    3. Created a Typescript script that would create a queue and perform an export of all queues:
      constructor(scope: Construct, id: string) {
        super(scope, id);
    
        // define resources here
        new GenesyscloudProvider(this,"genesyscloudprovider", {})
    
        new TfExport(this, "myexport", {
          directory: "./genesyscloud/export",
          resourceTypes: ["genesyscloud_routing_queue"],
          includeStateFile: true,
          exportAsHcl: true
        })
    
        new RoutingQueue(this, "mySimpleCDKQueue",{
          name: "MySimpleCDKQueue", 
          description: "Example Queue built by CDK"
        }) 
      }
    }
    
    
    
    const app = new App();
    
    new MyStack(app, "cdktf");
    app.synth();

    I ran cdktf deploy and everything worked as expected. So a couple of things:

    1. Make sure you do a cdktf deploy and not just a cdktf synth. I know that sounds really basic but I forgot to do that multiple times. :)
    2. Remember you are doing an export as a relative path your export files are going to be written out to the cdktf.out\stacks\fullExport directory.
    3. The TFExport object is a resource of the CX as Code provider. This means that when you run your typescript application it will generate a tfstate file that maintains the state for your run. The actual exported resources and a state file will be written to your export directory.

    I hope this helps. I am going to record a DevDrop that shows how to set up and use the Terraform CDK with CX as Code and Typescript. Keep an eye on the videos section of the Developer Center and it should be there sometime this week.

    Thanks, John Carnell Manager, Developer Engagement


    MiquelTrillaRomero | 2023-01-18 13:21:09 UTC | #7

    Thank you John!!

    Can you share your output file when you execute cdktf synth? can you also upload this dummy project so I can execute same code on my workstation? I still don't see what I'm doing wrong but no resource is generated on tfstate file when executing the cdksynth.


    John_Carnell | 2023-01-18 16:52:53 UTC | #8

    Hi Miguel,

    I threw the project out here in my personal account since I do not plan to turn this into a formal blueprint. I hope this helps.

    If you blow away the state files and then set the Genesys client credentials via environment variables you should be able to run this exact app. Also you can turn up the TFLOG=debug and set the SDK flag on the provider to get logs from the SDK calls and the TFLOG.

    Thanks, John Carnell Manager, Developer Engagement


    MiquelTrillaRomero | 2023-01-20 08:12:58 UTC | #9

    Thank you very much John :star_struck:!!!

    I will download the project, test on my laptop and let you know.


    MiquelTrillaRomero | 2023-01-20 14:23:04 UTC | #10

    Hi John,

    Finally I've found out the error, when creating the resources I was passing "scope" as parameter but I have to pass "this":

    wrong -> new TfExport(scope, "myexport", {

    correct -> new TfExport(this, "myexport", {

    Thank you very much for your help :smilingfacewiththreehearts:!!!


    John_Carnell | 2023-01-20 18:01:25 UTC | #11

    Hi Miquel,

    No worries. Glad you found it and I have been there debugging these issues. They can be slog.

    Thanks, John Carnell Manager, Developer Engagement


    system | 2023-02-20 18:02:07 UTC | #12

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


    This post was migrated from the old Developer Forum.

    ref: 17951