Convert Complex JSON to HCL

I have JSON as follows

        "redis_parameters": {
          "redis0": {
            "cluster_mode": {
              "num_node_groups": 2,
              "replicas_per_node_group": 1
            },
            "count": 0,
            "node_type": "cache.t3.small",
            "port": 6379
          }
        }

With defination as:

    variable "redis_parameters" {
      type = map(object({
        count     = number
        node_type = string
        port      = number
        cluster_mode = object({
          replicas_per_node_group = number
          num_node_groups         = number
        })
      }))
    }

I want to store the value into Terraform cloud workspace thru the TFE 
as 
    resource "tfe_variable" "redis" {
      key          = "redis_parameters"
      value        =var.redis_parameters -- what should go here?
      category     = "terraform"
      hcl          = true
      workspace_id = tfe_workspace.qa5.id
    }

How do convert HCL to string

Hi, welcome to the forum!

For the tfe_variable resource, when hcl = true you can provide any string literal with valid HCL. Given your JSON above, that’d look like this in HCL:

resource "tfe_variable" "redis" {
  key          = "redis_parameters"
  value        = <<HEREDOC
  {
    redis0 = {
      cluster_mode = {
        num_node_groups = 2
        replicas_per_node_group = 1
      }
      count = 0
      node_type = "cache.t3.small"
      port = 6379
    }
  }
  HEREDOC

  category     = "terraform"
  hcl          = true
  workspace_id = tfe_workspace.qa5.id
}

That will show up in the Terraform Cloud UI like this, on that workspace:

Hope that helps!