OpsCanary
observabilitygrafanaPractitioner

Monitoring HCP Terraform with Grafana Cloud: A Practical Guide

5 min read Grafana BlogReviewed for accuracy
Share
PractitionerHands-on experience recommended

In today's cloud-native landscape, observability is not just a nice-to-have; it's a necessity. Monitoring HCP Terraform and Terraform Enterprise with Grafana Cloud allows you to capture critical performance data, enabling proactive management of your infrastructure. By leveraging OpenTelemetry, you can gain insights into your Terraform runs, ensuring that you can quickly identify and resolve issues before they impact your operations.

The process begins with HCP Terraform dispatching a run to a self-hosted agent. This agent sends traces and metrics over the OpenTelemetry Protocol (OTLP) and logs via the Docker Engine API to Alloy. Alloy then exports these signals to Grafana Cloud, where you can visualize and analyze them. Key configuration parameters include TFC_AGENT_OTLP_ADDRESS, which points to Alloy's OTLP receiver, and GRAFANA_CLOUD_URL, which directs where the telemetry data should be sent. You’ll also need to set environment variables for your Grafana Cloud instance ID and access token to authenticate the data flow.

In production, you can run Alloy and the HCP Terraform agent in various ways, but using Docker Compose simplifies the setup. Ensure you have the necessary prerequisites, including a Grafana Cloud account and the Terraform CLI installed. Be mindful that the telemetry activation hinges on the TFC_AGENT_OTLP_ADDRESS parameter, which is crucial for data transmission. Also, remember that while this setup is straightforward, it can become complex if not managed properly, especially when scaling your infrastructure.

Key takeaways

  • Configure TFC_AGENT_OTLP_ADDRESS to point at Alloy's OTLP receiver for telemetry.
  • Set GRAFANA_CLOUD_URL to your Grafana Cloud OTLP endpoint for data export.
  • Utilize Docker Compose for an easy and reproducible setup of Alloy and the HCP Terraform agent.
  • Ensure your Grafana Cloud access token has the necessary scopes for metrics, logs, and traces.

Why it matters

Effective monitoring with Grafana Cloud can drastically reduce downtime and improve your team's response time to incidents. This setup provides a comprehensive view of your Terraform operations, leading to better decision-making and resource management.

Code examples

plaintext
1// tfc-agent pushes traces + metrics here (OTLP gRPC).
2otelcol.receiver.otlp "default" {
3 grpc {
4   endpoint = "0.0.0.0:4317"
5 }
6 output {
7   metrics = [otelcol.processor.deltatocumulative.default.input]
8   traces  = [otelcol.processor.batch.default.input]
9 }
10}
11
YAML
1services:
2 alloy:
3   image: grafana/alloy:latest
4   user: root
5   command:
6     - run
7     - --server.http.listen-addr=0.0.0.0:12345
8     - --stability.level=experimental
9     - /etc/alloy/config.alloy
10   environment:
11     GRAFANA_CLOUD_INSTANCE_ID: "${GRAFANA_CLOUD_INSTANCE_ID}"
12     GRAFANA_CLOUD_TOKEN: "${GRAFANA_CLOUD_TOKEN}"
13     GRAFANA_CLOUD_URL: "${GRAFANA_CLOUD_URL}"
14   volumes:
15     - ./config.alloy:/etc/alloy/config.alloy
16     - /var/run/docker.sock:/var/run/docker.sock:ro
17   ports:
18     - "4317:4317"
19     - "12345:12345"
20
plaintext
# Start Alloy and the agent
docker compose -f docker-compose.yml up -d

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →
DigitalOcean Serverless InferenceSponsor

OpenAI & Anthropic-compatible inference API — no GPU provisioning needed. 55+ models, pay-per-token with no minimums. VPC + zero data retention by default.

Try Serverless Inference →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.