Terraform
- Terraform Enterprise
- 1.0.x (latest)
- v202506-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`.
Azure Managed Identity requirements
Use Azure Managed Identity to authenticate with Azure Database for PostgreSQL. Here are a few requirements:
- The managed identity must be able to access the database from the virtual machine.
- The managed identity must have the required permissions on the database.
Note
Terraform Enterprise does not support workload identities for authentication.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.
Configure authentication settings
You can use the following authentication methods so that Terraform Enterprise can communicate with the database.
Username and password authentication
You can configure Terraform Enterprise to use the database's user and password to authenticate with the server.
Set the TFE_DATABASE_USER and TFE_DATABASE_PASSWORD variable for username and password based authentication.
Client certificate authentication
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.
Azure MSI authentication
You can use both system-assigned and user-assigned managed identities to authenticate to Azure Database for PostgreSQL flexible server. Refer to the Azure documentation for more information. When using Azure MSI authentication, the database password is not required.
Configure the following settings to use Azure MSI:
- Set the TFE_DATABASE_PASSWORDLESS_AZURE_USE_MSIvariable totrue.
- Set the TFE_DATABASE_PASSWORDLESS_AZURE_CLIENT_IDto the client ID of the user-assigned managed identity. Leave it blank to use the system-assigned managed identity.
- Set the TFE_DATABASE_USERto the managed identity name.
Ensure that the managed identity has the required permissions on the database. If you migrate from password-based authentication to MSI, the previous user may own the database and schemas. Reassign ownership or grant the necessary permissions to the managed identity user.