Genesys Cloud & Terraform Cloud

Hi there,

I want to leverage Terraform Cloud in order to start managing a Genesys Cloud Org specific configuration.
What I did:

  1. Created my Terraform Cloud account
  2. Successfully bound my Terraform Cloud account with my GitHub account.
  3. Put a main.tf file and resources.tf to my GitHub repo:

resources.tf looks like this

resource "genesyscloud_tf_export" "include-filter" {
export_as_hcl = true
directory = "./genesyscloud"
log_permission_errors = true
include_state_file = true
include_filter_resources = ["genesyscloud_user"]
}

main.tf looks as follows

terraform {
required_providers {
genesyscloud = {
source = "MyPureCloud/genesyscloud"
version = "1.26.0"
}
}
}

provider "genesyscloud" {
oauthclient_id = ""
oauthclient_secret = ""
aws_region = "eu-central-1"
}

Goal was to do an export of current user configuration and start managing users only via Terraform, hence I have state_file set to enabled.

  1. The commit on GitHub has triggered the Terraform Cloud Run, which was successfull.

However:

The only state file I got is the following:

{
"version": 4,
"terraform_version": "1.11.1",
"serial": 7,
"lineage": "e3788261-b163-8d54-4307-dfb95ba31daa",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "genesyscloud_tf_export",
"name": "include-filter",
"provider": "provider["registry.terraform.io/mypurecloud/genesyscloud"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"directory": "./genesyscloud",
"enable_flow_depends_on": false,
"exclude_attributes": null,
"exclude_filter_resources": null,
"export_as_hcl": true,
"id": "./genesyscloud",
"include_filter_resources": [
"genesyscloud_user"
],
"include_state_file": true,
"log_permission_errors": true,
"resource_types": null,
"split_files_by_resource": false
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
}
],
"check_results": null
}

If I do the same locally in my machine via CLI an additional directory will be created called "genesyscloud" and there I see the tf.json file and tfstate file where both contain the real resources I want to manage later on.

When doing this via cloud I don't see those.

Where are the tf.json and the genuine tfstate file are supposed to be placed when running terraform via cloud?

Has anyone tried this already?

Maybe I did something wrong......

Look forward to hear from you.

BR,
Mat

The way I would do this is to do the export locally then pull down your .tfstate from Terraform cloud and move your resources from the state from the export to the state you pulled down and then push the state back to Terraform Cloud.

I believe you will also need to target the specifc Terraform Workspace in the terraform block as below

terraform {
  cloud {
    organization = "Your-Org"
    workspaces {
      name = "Your-Workspace"
    }
  }
  required_providers {
    genesyscloud = {
      source  = "mypurecloud/genesyscloud"
      version = "1.59.1"
    }
  }
}

Thanks for your response.
Would that also mean that I would need to work on the corresponding tf.json file only locally in order to make changes towards the org and also push it to the terraform cloud workspace?
Terraform would need then to compare it with the tfstate file already pushed to the cloud.
Do you know if Terraform cloud also stores the tf.json file?

Once you have pulled your state from the cloud and moved your resources from the exported state to the local state from TF cloud. You can then push that state file to the cloud using

terraform state push terraform.tfstate

This will then overwrite your state in the cloud with the local copy. You can then delete the two local states, and as long as your Terraform Cloud workspace is connected to your GitHub branch, you can then manage those resources via your configuration in your tf.json files. When you push changes to your branch, it will trigger a plan in Terraform Cloud (If you have this turned on).