How to do remote-exec operation if i am using terraform cloud

Surely you can add private key as a variable in terraform cloud and then use that? Eg

variable "tf_cloud_ssh_private_key" {
  type        = string
  description = "(optional) Private SSH key defined as a workspace variable in terraform cloud"
  default     = null
}

connection {
  type        = "ssh"
  user        = "ubuntu"
  private_key = var.tf_cloud_ssh_private_key != null ? var.tf_cloud_ssh_private_key : file("private_keys/${var.keypair_name}.pem")
  host        = aws_instance.bastion[0].public_ip
}