Terraform Enterprise Log Forwarding
Terraform Enterprise supports forwarding its logs to one or more external destinations, a process called log forwarding. Log forwarding provides increased observability, assistance complying with log retention requirements, and information during troubleshooting.
Requirements
Log forwarding requires:
- Terraform Enterprise running on an instance using
systemd-journald
. Executesystemctl status systemd-journald
to check if thesystemd-journald
service is started and enabled. - A version of Docker that supports the
journald
logging driver. Executedocker info --format '{{.Plugins.Log}}'
to check if thejournald
plugin is listed. - Network connectivity between Terraform Enterprise and the external destination(s) where logs should be forwarded.
Enable Log Forwarding
Log forwarding is disabled by default. To enable log forwarding, set the
log_forwarding_enabled
Terraform Enterprise application setting to the value
1
.
When log forwarding is enabled, the Terraform Enterprise application settings
show the following for log_forwarding_enabled
:
Note: Automated license utilization reporting (which securely sends HashiCorp the minimum data required to validate license utilization) is on by default.
Configure External Destinations
The log_forwarding_config
Terraform Enterprise application setting must
contain valid
Fluent Bit [OUTPUT]
configuration
specifying
supported external destination(s)
where Terraform Enterprise should forward logs. The default configuration does
not forward any logs.
Since the Terraform Enterprise application settings are stored as JSON
strings, we recommend first creating a fluent-bit.conf
file with the valid
Fluent Bit [OUTPUT]
configuration and then using that file to configure the
log_forwarding_config
application setting. This method ensures that the
configuration is stored in the application settings exactly how it appears in
the fluent-bit.conf
file.
For a Standalone installation of Terraform Enterprise:
For an Active/Active installation of Terraform Enterprise:
Once configured, the Terraform Enterprise application settings show the
log_forwarding_config
setting in escaped JSON string format:
That escaped JSON string renders to the following:
To forward logs to multiple external destinations, use multiple [OUTPUT]
directives.
Note: Do not use an [OUTPUT]
directive with the
stdout
Fluent Bit output plugin.
Doing this creates a loop that continuously emits logs!
Restart Terraform Enterprise
Once log forwarding is enabled and configured, you need to restart Terraform Enterprise for the changes to take effect. Learn how to restart Terraform Enterprise.
Supported External Destinations
You can only forward logs to one of the supported external destinations below. Each supported external destination contains example configuration for convenience.
Amazon CloudWatch
Sending to Amazon CloudWatch is only supported when Terraform Enterprise is located within AWS due to how Fluent Bit reads AWS credentials.
This example configuration forwards all logs to Amazon CloudWatch. Refer to the
cloudwatch_logs
Fluent Bit output plugin documentation
for more information.
Note: In Terraform Enterprise installations using AWS external services,
Fluent Bit will have access to the same AWS_ACCESS_KEY_ID
and
AWS_SECRET_ACCESS_KEY
environment variables that are used for object storage.
Amazon S3
Sending to Amazon S3 is only supported when Terraform Enterprise is located within AWS due to how Fluent Bit reads AWS credentials.
This example configuration forwards all logs to Amazon S3. Refer to the
s3
Fluent Bit output plugin documentation
for more information.
Note: In Terraform Enterprise installations using AWS external services,
Fluent Bit will have access to the same AWS_ACCESS_KEY_ID
and
AWS_SECRET_ACCESS_KEY
environment variables that are used for object storage.
Azure Blob Storage
This example configuration forwards all logs to Azure Blob Storage. Refer to the
azure_blob
Fluent Bit output plugin documentation
for more information.
Azure Log Analytics
This example configuration forwards all logs to Azure Log Analytics. Refer to
the azure
Fluent Bit output plugin documentation
for more information.
Datadog
This example configuration forwards all logs to Datadog. Refer to the
datadog
Fluent Bit output plugin documentation
for more information.
Forward
This example configuration forwards all logs to a listening Fluent Bit or
Fluentd instance. Refer to the
forward
Fluent Bit output plugin documentation
for more information.
Google Cloud Platform Cloud Logging
Sending to Google Cloud Platform Cloud Logging is only supported when Terraform Enterprise is located within GCP due to how Fluent Bit reads GCP credentials.
This example configuration forwards all logs to Google Cloud Platform Cloud
Logging (formerly known as Stackdriver). Refer to the
stackdriver
Fluent Bit output plugin documentation
for more information.
Note: In Terraform Enterprise installations using GCP external services,
Fluent Bit will have access to the GOOGLE_SERVICE_CREDENTIALS
environment
variable that points to a file containing the same GCP Service Account JSON
credentials that are used for object storage.
Splunk Enterprise HTTP Event Collector (HEC)
This example configuration forwards all logs to Splunk Enterprise via the HTTP
Event Collector (HEC) interface. Refer to the
splunk
Fluent Bit output plugin documentation
for more information.
Syslog
This example configuration forwards all logs to a Syslog-compatible endpoint.
Refer to the
syslog
Fluent Bit output plugin documentation
for more information.
Warning
The `syslog_message_key` should not be changed from `message`. If that value is changed, the application will no longer forward logs.Audit Logs
Terraform Enterprise emits its audit logs along with its application logs.
Currently, log forwarding can forward either all Terraform Enterprise logs or no
logs at all. To distinguish audit logs from application logs, audit log entries
contain the string [Audit Log]
.
Here's an example audit log entry formatted for readability:
If you have a requirement to split audit logs from application logs, we
recommend forwarding all Terraform Enterprise logs to a log aggregation system,
filtering the audit logs based on the [Audit Log]
string, and forwarding just
the audit logs to the desired destination.
Log Rotation
Log forwarding uses the journald
Docker logging driver to send Terraform
Enterprise logs to systemd-journald
. This can cause increased disk utilization
for the /var/log/journal
path.
To limit disk utilization, configure the SystemMaxFileSize
and
SystemMaxFiles
settings within /etc/systemd/journald.conf
.
The following configuration tells systemd-journald
to use up to 7GB of disk
space by limiting the size a log file to 1024MB and keeping up to 7 files at any
given time:
To apply these changes, restart systemd-journald
: