Introduction
This guide describes how to connect to the PostgreSQL database from a Terraform Enterprise container for various installation types. This is useful for direct database inspection or troubleshooting.
Prerequisites
- Administrative access to the host machine where the Terraform Enterprise container is running.
Procedure
This procedure varies depending on your Terraform Enterprise installation method. Select the option that matches your environment.
Option 1: Replicated Non-Consolidated Installation
Access the
tfe-atlascontainer shell.$ sudo docker exec -ti tfe-atlas /bin/bash
Connect to the database using the
psqlclient with the predefined connection string.# psql $DATABASE_URL
Option 2: Replicated Consolidated Installation
Access the
terraform-enterprisecontainer shell.$ sudo docker exec -ti terraform-enterprise /bin/bash
Connect to the database using the
psqlclient and the environment variables for the connection string.# psql postgres://$TFE_DATABASE_USER:$TFE_DATABASE_PASSWORD@$TFE_DATABASE_HOST/$TFE_DATABASE_NAME?$TFE_DATABASE_PARAMETERS
Option 3: Docker FDO (Mounted Disk) Installation
Access the
terraform-enterprisecontainer shell.$ sudo docker exec -ti terraform-enterprise /bin/bash
Connect to the database using the
psqlclient with the default credentials.# psql -U hashicorp -d hashicorp
Option 4: Docker FDO (External or Active/Active) Installation
Access the
terraform-enterprise-tfe-1container shell.$ docker exec -ti terraform-enterprise-tfe-1 bash
Connect to the database using the
psqlclient and the environment variables for the connection string.# psql postgres://$TFE_DATABASE_USER:$TFE_DATABASE_PASSWORD@$TFE_DATABASE_HOST/$TFE_DATABASE_NAME?$TFE_DATABASE_PARAMETERS
Option 5: Kubernetes FDO Installation
Get the details for the Terraform Enterprise pod.
$ kubectl get pods -n terraform-enterprise
The command returns output similar to the following.
## Example output NAME READY STATUS RESTARTS AGE terraform-enterprise-bcc6bbb9f-9qqkj 1/1 Running 0 14m
Connect to the running Terraform Enterprise pod. Replace the example pod name with the one from your environment.
$ kubectl exec --stdin --tty terraform-enterprise-bcc6bbb9f-9qqkj -n terraform-enterprise -- /bin/bash
Connect to the database using the
psqlclient and the environment variables for the connection string.# psql postgres://$TFE_DATABASE_USER:$TFE_DATABASE_PASSWORD@$TFE_DATABASE_HOST/$TFE_DATABASE_NAME?$TFE_DATABASE_PARAMETERS
Additional Information
For more details on managing your Terraform Enterprise installation, refer to the official Terraform Enterprise documentation.