hashicorp / terraform-k8s

Terraform Cloud Operator for Kubernetes
https://learn.hashicorp.com/tutorials/terraform/kubernetes-operator?in=terraform/kubernetes
Mozilla Public License 2.0
454 stars 71 forks source link

Customize workspace name #135

Open OlegGorj opened 2 years ago

OlegGorj commented 2 years ago

Community Note

Description

Presently, the name of TFE/TFC workspace gets constructed using k8s Namespace and Name specified in CRD ref: https://github.com/hashicorp/terraform-k8s/blob/0c0b52b36cfff48a1ca721707e65115800593561/workspacehelper/workspace_helper.go#L128 . Provided, in multi-tenant with vast complexity environments, namespaces can be quite long and descriptive, that makes the construct of the workspace name quite lengthy, hence ability to override the name of the workspace to shorten it, would be quite of utility.

Potential Terraform Configuration

In case of k8s namespace as my-very-lengthy-namespace-0 combined with workspace from CRD as demo, makes actual TFC workspace my-very-lengthy-namespace-0-demo. By specifying key tfc_name one could shorten the name to my-ns0-demo.

apiVersion: app.terraform.io/v1alpha1
kind: Workspace
metadata:
 name: demo

 # 
 #  Shorter name of the workspace 
 #
 tfc_name: my-ns0-demo

spec:
 organization: demo
 secretsMountPath: "/tmp/secrets"
 variables:
   - key: CONFIRM_DESTROY
     value: "1"
     sensitive: false
     environmentVariable: true
 outputs:
   - key: pet
     moduleOutputName: rofl

References

n/a

jtyr commented 2 years ago

You can specify omitNamespacePrefix in the Workspace resource that will omit the namespace from the name of the TFC Workspace. Then the Workspace is names as the Workspace resource is named:

...
metadata:
  name: my-ns0-demo
...
spec:
  omitNamespacePrefix: true
  ...