I have an existing workspace setup on app.terraform.io with VCS integration (GitLab) and some terraform variables. I want to create a new workspace out of it but this new workspace runs from a different branch. Can we clone existing workspace to avoid copying all the variables and other settings again to save time.
I don’t want to copy state but only VCS settings and Terraform variables. After cloning the workspace, I will only change the branch to run terraform against. For now, my Terraform variables may remain same but are guaranteed to change.
If you want to copy over Terraform Variables, I know of a tool for this.
It’s probably not relevant to your case, but I have used and recommended tfh to clients, in the past, for copying over Variables and Values from one Terraform Enterprise workspace to another:
However, it does not copy the values for Sensitive Variables, because these are stored in Vault with a write-only policy.
I guess you could even write your own scripts for this, because tfh pretty much just wraps the Terraform Enterprise API.
If this is something you do frequent, perhaps it’s worth checking out and converting to variable sets? (see link).
We here use terraform to create all workspaces (That was way prior they had the variable sets). We have one bootstrap workspace called terraformio with all variables we ever need defined there. Then we have code like this:
locals {
workspaces = {
test = {
"name" = "my-test"
"work_dir" = "my-terraform"
"branch" = "feature/test"
"vcs_id" = "test/myterraform"
"ingress_submodules" = false
"terraform_version" = "1.0.11"
variables = [
{
# name of the var in target namespace
name = "MY_VAR"
# value of this var, taken from the value of the var defined in this bootsrap workspace
value = var.VAR_DEFINED_IN_THIS_WORKSPACE
is_sensitive = true
},
]
}
}
}
Then we loop over this stuff and all is there.
We want to move to variable sets but currently I see no support for these in tfe_ provider so we are delaying.