Deploy Terraform Enterprise to OpenShift
This topic describes how to deploy Terraform Enterprise to Red Hat OpenShift. You should have a deep understanding of OpenShift before deploying Terraform Enterprise to a production environment.
Overview
Deploy external service dependencies outside the OpenShift cluster and scale as necessary to accommodate Terraform Enterprise workloads. The following diagram shows the Terraform Enterprise architecture when deployed to OpenShift-orchestrated containers:
Complete the following steps to install Terraform Enterprise:
- Complete the prerequisites.
- Create a custom Terraform cloud agent.
- Enable the OpenShift configuration your overrides values file.
- Install the Helm chart and apply your override values.
- Complete post installation tasks.
Prerequisites
Complete the following tasks before attempting to install Terraform Enterprise.
Prepare the deployment environment
Provide a DNS hostname for Terraform Enterprise and the associated TLS certificate. Additionally, you must configure your network so that your host can receive and send traffic. Refer to Prepare the host environment for details about preparing the host environment.
Deploy external storage systems
Deploy the database and other storage devices so that Terraform can connect to them when the application starts. Refer to Data storage settings overview for additional information.
Create the deployment configuration
Create a custom YAML configuration file, for example /tmp/overrides.yaml
, to override the default values in the Terraform Enterprise Helm chart. The file contains settings for the operational mode, license, TLS certificates, and network configuration. Specify any additional configurations necessary for your environment. Refer to the deployment configuration reference for additional information.
Externalizing secret values
The Terraform Enterprise deployment configuration requires several secret values, such as keys, passwords, and certificates. You can populate these as part of the Helm overrides.yaml
created before installation. However, this requires manual handling of secret values and may leave them exposed on the deployment host without further intervention.
To mitigate this security concern, HashiCorp recommends populating these secret values into a Kubernetes Secret from a centralized secrets management platform using a trusted orchestrator like the Vault Secrets Operator before installing Terraform Enterprise.
You can then reference the Kubernetes Secret in the Terraform Enterprise Helm Chart:
Create a custom Terraform cloud agent
Per the default restricted security context constraints, OpenShift requires containers run under a unique user ID. Refer to the OpenShift documentation for additional information about the security context constraints.
Create a custom tfc-agent
image in order to perform Terraform operations in Terraform Enterprise workspaces in compliance with the security context constraints. The image creates the default working directory for the tfc-agent
and assigns permissions to the root group.
Place the following tfc-agent
image configuration in a container registry that is accessible to the OpenShift nodes hosting Terraform Enterprise:
Note that custom images sourced from tfc-agent
s cannot use automatic CA certificate injection. As a result, you may need to add CA certificate injection configuration to the Dockerfile.
In your deployment configuration file, configure the following environment variables to enable Terraform Enterprise to use the custom image:
Refer to the deployment configuration reference for information about all configuration settings.
Enable OpenShift
In your overrides YAML file, set the openshift.enabled
value to true
so that Terraform Enterprise starts each Terraform Enterprise service as the OpenShift-assigned container entry user ID.
By default, the Terraform Enterprise Helm chart applies the following security context configuration so that Terraform Enterprise complies with OpenShift's restricted security context constraint:
Install Terraform Enterprise with Helm
Connect to the host instance.
Log in to the Terraform Enterprise container image registry.
Pull the Terraform Enterprise image from the registry.
Create a new project.
Create an image pull secret in
<TFE_PROJECT>
to fetch theterraform-enterprise
container from the<DOCKER_REGISTRY_URL>
. This URL can beimages.releases.hashicorp.com
, or your internal container registry. If you are usingimages.releases.hashicorp.com
, useterraform
as the<DOCKER_REGISTRY_USERNAME>
parameter in the following command with--docker-password=$(cat /path/to/terraform.hclic)
Add the Hashicorp Helm registry:
Render the
terraform-enterprise
chart with your custom values file<OVERRIDES_FILE>
, for exampletmp/overrides.yaml
.Install
terraform-enterprise
, this step can take several minutes.Inspect
terraform-enterprise
pods to verify their successful start.If Terraform Enterprise pods fail to start, refer to Kubernetes Troubleshooting.
By default, Terraform Enterprise installs a load balancer service. Retrieve the external IP address of this service.
Set up a DNS record that points to your external IP address to enable routing to your
<TFE_HOSTNAME>
. A DNS address is required to communicate with Terraform Enterprise, and it is managed outside of OpenShift and the Terraform Enterprise helm chart or application.Validate the readiness of the Terraform Enterprise application by querying the health check endpoint.
Post installation tasks
Complete the following tasks after the initial installation.
Review startup checks
When you start Terraform Enterprise, several startup checks also run to prevent errors related to invalid configurations or certificates, as well as other issues that could prevent the application from running successfully or safely. Refer to the startup checks reference for additional information.
Configuring a route
When you deploy Terraform Enterprise to OpenShift, the Helm chart does not create an OpenShift route by default.
Provisioning a route creates a public-facing URL at which users can access the Terraform Enterprise UI and API.
Note: Use the options on the oc expose
command to tailor the route to the needs of your environment.
The newly created route can then be retrieved from the cluster:
Create the initial admin user
Provision your first administrative user and start using Terraform Enterprise.
Extend or fork the OpenShift terraform-enterprise
helm chart
The Terraform Enterprise Helm Chart is intended to meet the needs of the majority of our users. Many OpenShift primitives, such as routing, are absent in the terraform-enterprise
Helm chart. You can fork our Helm chart and adapt it to your organization’s requirements. Alternatively, you can use the terraform-enterprise
Helm chart as a sub-chart, thus relegating OpenShift primitives to the parent chart to be deployed around the terraform-enterprise
chart contents.
If you contact HashiCorp support, include your custom Helm chart alongside your support bundle to ensure support has all the information they need.
Example deployment configuration
The following example configuration deploys Terraform Enterprise to OpenShift in Azure with hosted external services. The configuration is based on cloud native hosted PostgreSQL, storage, or Redis cache services. You can copy the example configuration and modify the values to per your environment. Refer to Configuration Reference for a list of all configuration options.
The example also depends on the following conditions:
Values under
.env.variables
are set as aConfigMap
and mounted as Terraform Enterprise environment variables.Values under
.env.secrets
are set as Kubernetes secrets and mounted as Terraform Enterprise environment variables.Extend the
env.configMapRefs[]
orenv.secretRefs[]
with your own resources to add additionalConfigMap
orSecret
resources within your environment configuration.Values marked
BASE_64_ENCODED*
indicate that the value given must be base 64 encoded. If you are using this certificate configuration to host Terraform Enterprise web traffic, this value must be valid with theenv.TFE_HOSTNAME
, or match the wildcard pattern.
Refer to the following materials for additional guidance on setting up Helm chart values files:
- Terraform Enterprise Helm repository
- Release version tags
- Generic reference for values file to override the default values in the Helm chart.