Terraform
- Terraform Enterprise
- 1.0.x (latest)
- v202507-1
- v202505-1
- v202504-1
- v202503-1
- v202502-2
- v202502-1
- v202501-1
- v202411-2
- v202411-1
- v202410-1
- v202409-3
- v202409-2
- v202409-1
- v202408-1
- No versions of this document exist before v202408-1. Click below to redirect to the version homepage.
- v202407-1
- v202406-1
- v202405-1
- v202404-2
- v202404-1
- v202402-2
- v202402-1
- v202401-2
- v202401-1
- v202312-1
- v202311-1
- v202310-1
- v202309-1
- v202308-1
- v202307-1
- v202306-1
- v202305-2
- v202305-1
- v202304-1
- v202303-1
- v202302-1
- v202301-2
- v202301-1
- v202212-2
- v202212-1
- v202211-1
- v202210-1
- v202209-2
- v202209-1
- v202208-3
- v202208-2
- v202208-1
- v202207-2
- v202207-1
- v202206-1
Connect to an external PostgreSQL database
This topic describes how to configure Terraform Enterprise to connect to an external PostgreSQL database. You only need to complete this task under the following conditions:
- You want to operate Terraform Enterprise in active-activeorexternalmode, which instructs Terraform Enterprise to store and retrieve data in an externally-managed database. Refer to Configure operational mode for additional information.
- You want to connect to a single PostgreSQL node. To connect Terraform Enterprise to an HA PostgreSQL database cluster, refer to Connect to a highly-available PostgreSQL cluster.
Overview
Complete the following steps to connect Terraform Enterprise to a single PostgreSQL node:
- Create extensions for the database schemas.
- Specify the connection settings in your deployment configuration. If your server requires additional connection parameters, you must also specify them in the configuration.
Requirements
Before proceeding, verify that you meet the following requirements.
Server
One of the following servers is required:
- PostgreSQL server, such as Amazon RDS for PostgreSQL, version 13.x, 14.4 and up, 15.x or 16.x - Note Note that PostgreSQL v12 will reach end of life on November 12, 2024. As a result, Terraform Enterprise will no longer allow v12 after that date.
- PostgreSQL-compatible server, such as Amazon Aurora PostgreSQL. 
User
Create a PostgreSQL user with the following permissions on the database:
- Permissions to create, modify, and read all tables and indices on all schemas within the database. Database owners commonly have these permissions. 
- Permissions to create extensions. If you are unable to create a user with the - CREATE EXTENSIONprivilege, refer to Create extensions for instructions on creating the necessary extensions.
- The - rails,- vault,- registry,- task_worker, and- terraform_enterprisePostgreSQL schemas are required. We recommend allowing the PostgreSQL user to create schemas so that Terraform Enterprise can create them automatically. If the PostgreSQL user does not have permissions to create schemas, they must be created prior to installation.- Note Note that if you are changing the database user, ensure the new user is the owner of all enum types in the database to avoid failures for any potential migrations that attempt to `ALTER TYPE`.
Create extensions
Create extensions for the rails, vault, registry, and task_worker
PostgreSQL schemas. The database server automatically creates these schemas if
they do not already exist.
Run the following commands on the PostgreSQL server to create the extensions:
CREATE EXTENSION IF NOT EXISTS "hstore" WITH SCHEMA "rails";
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA "rails";
CREATE EXTENSION IF NOT EXISTS "citext" WITH SCHEMA "registry";
Specify PostgreSQL connection settings
Add the following settings to your Terraform Enterprise configuration:
- Set the TFE_DATABASE_HOSTvariable to the location of your PostgreSQL server. Format the location asHOST[:PORT], for exampledb.example.comordb.example.com:5432. Multi host connection strings are not supported.
- Set the TFE_DATABASE_NAMEvariable to the name of the database you want to store the data in.
- Set the TFE_DATABASE_USERvariable to the user name you want to use to access the database.
- Set the TFE_DATABASE_PASSWORDvariable to the password for the user.
Refer to Database settings in the configuration reference for additional information.
Additional connection parameters
Add the TFE_DATABASE_PARAMETERS variable to your configuration and specify any
additional connection parameters necessary to connect to the server.
sslmode
When providing extra keyword parameters for the database connection, the
sslmode parameter only allows the following values:
When operating Terraform Enterprise in external mode, the sslmode parameter
is set to require by default. When operating Terraform Enterprise in disk
mode, the sslmode parameter is set to disable by default.
Terraform Enterprise provides a certificates file at
/etc/ssl/private/terraform-enterprise/bundle.pem, which is required by the
verify-full and verify-ca modes.
Refer to the
PostgreSQL library documentation
for additional information about using sslmode.
Client certificate configuration
You can configure Terraform Enterprise to use PostgreSQL client certificates to authenticate with the server. When providing client certificates, the database password is not required and the sslmode parameter is set to verify-full.
Terraform Enterprise requires PostgreSQL server certificate to use Subject Alternative Names (SANs) rather than relying solely on the legacy Common Name field.
Configure the following settings to use PostgreSQL client certificates:
- Set the TFE_DATABASE_USE_MTLSvariable totrue.
- Specify the path to the CA certificate file in the TFE_DATABASE_CA_CERT_FILEvariable.
- Specify the path to the client certificate file in the TFE_DATABASE_CLIENT_CERT_FILEvariable.
- Specify the path to the client key in the TFE_DATABASE_CLIENT_KEY_FILEvariable.