Manage observability configurations as code with the Splunk Observability Cloud Terraform provider
- Last updated
- Save as PDF
As applications evolve beyond the early stages of development, their architectures become increasingly complex. This is especially true in continuous integration and continuous deployment (CI/CD) environments, where configurations change frequently. In fast-moving, large-scale environments, manually tracking every code change, infrastructure update, or observability configuration is not practical.
Terraform is a widely used Infrastructure as Code (IaC) tool developed by Hashicorp. It addresses these challenges by automating infrastructure management, integrating configurations into version control systems, and reducing manual intervention.
In this article, you'll learn about:
- What Terraform is and how it works.
- Benefits of using Terraform, particularly for observability.
- Implementation of the Splunk Observability Cloud Terraform provider for observability as code.
Terraform: overview and benefits
Instead of manually configuring infrastructure through user interfaces (UIs) or command-line interactions, Terraform allows for provisioning and management via code. This allows development teams to apply software development best practices to infrastructure management, improving maintainability and scalability. Terraform uses human-readable configuration files (*.tf) to define the desired state of infrastructure, while plugins, known as providers, allow integration with cloud platforms and services to define pieces of infrastructure. The Terraform Registry offers over 1,000 providers for AWS, Azure, Google Cloud Platform (GCP), Kubernetes, Splunk, and other services.
Terraform automates the infrastructure management process, reducing manual provisioning efforts that are error-prone and time-consuming. Teams can build, change, and manage infrastructure in a version-controlled, shared, and repeatable way all from a centralized Terraform file. This file can be committed and stored alongside existing code in tools such as GitHub or GitLab for safe and collaborative infrastructure management. Additionally, multiple cloud platforms can be managed from within the same Terraform file, eliminating the need to manually move between different configuration interfaces. Terraform's human-readable syntax simplifies configuration, and its state file maintains infrastructure changes for accurate tracking and management.
Terraform is designed for ease of use. After installing Terraform, users can initiate a configuration with a main.tf
file and a few commands to initialize, preview, and apply their infrastructure plan.
Terraform and observability
Observability configurations, like infrastructure components, can be managed as code using Terraform. Instead of manually creating dashboards, charts, alerts, or cloud platform integrations through an observability UI, these resources can be defined, versioned, and deployed using Terraform. This approach offers several advantages, explained in the next few sections.
Standardization and consistency
Terraform configurations can be structured into reusable modules, allowing teams to define observability resources consistently across multiple services and environments. Standardized dashboards, alerts, and charts improve visibility and facilitate troubleshooting. Manual configuration introduces inconsistencies and increases the likelihood of errors, whereas Terraform ensures uniformity and prevents configuration drift.
Collaboration and improved maintenance
Managing observability as code provides version control, audit logs, and a structured change approval process. Unlike manual UI-based changes, Terraform configurations require check-in and approval through a version control system such as GitHub or GitLab. This ensures transparency, prevents conflicting changes, and enables controlled rollbacks if needed.
Scalability and efficiency
Terraform centralizes observability configurations alongside code repositories, reducing the need for manual updates through UI interactions. Instead of navigating through multiple dashboards to adjust alert thresholds, users can modify configurations in the Terraform codebase and redeploy. Terraform facilitates bulk updates across multiple environments, eliminating repetitive manual adjustments.
While managing dashboards and charts through Terraform might seem complex, it is highly beneficial in microservices architectures. Each microservice typically exists across multiple environments (for example, development, staging, production), and defining observability configurations in code enhances deployment speed and accelerates issue detection.
Security enhancements
Observability as code enhances security by centralizing credential management. Instead of distributing observability platform credentials across multiple team members, Terraform securely stores API keys and manages them within a controlled environment alongside other infrastructure secrets.
Creating observability resources using the Splunk Observability Cloud Terraform provider
Let’s see how to create observability resources using the Splunk Observability Cloud Terraform provider.
If you don’t already have Terraform installed, you must do that first. Check the Terraform documentation for tutorials.
- Create a new
main.tf
file in the application’s root directory or modify an existing Terraform file. Here is an example configuration for the Splunk Observability Cloud Terraform provider: - Define the
required_providers
block to declare provider dependencies, specifically thesignalfx
provider for Splunk Observability Cloud. You can think of therequired_providers
block like animport
statement, while the following provider-specific block configures thesignalfx
provider.If your Splunk organization is located in
us1
instead of the defaultus0
, specify theapi_url
. - Define
resource
blocks to create observability objects such as dashboards, detectors, or charts. Refer to the Splunk Observability Cloud Terraform provider docs under the Resources section for information on all available configurable resources. - Run
terraform init
to initialize Terraform and install the Splunk Observability Cloud provider. - Run
terraform plan
to preview the actions Terraform will perform after the configuration is applied. - Run
terraform apply
to create your resources. In this example, we're creating a dashboard group and dashboard. - Verify that your resources have been successfully created in the Splunk Observability Cloud UI.
- Although you've created the resources, these aren't too useful to you yet as there's no information within them that can help you on your observability journey. To add new resources or update existing ones, you can edit your main.tf file. The example below shows edits made to
main.tf
to add a chart resource and update the dashboard. - Run
terraform plan
to preview the changes. - Apply the changes using
terraform apply
and verify the chart in the dashboard.
Next steps
Whether you’re building out detectors and alerts, dashboards and charts, or integrating cloud services via Terraform, managing observability configurations as code can improve resource consistency, collaboration, and maintenance while increasing development and incident resolution speed.
If you’re new to Terraform, these resources might help you understand and implement this guidance:
- YouTube: Introduction to the Splunk Terraform provider
- YouTube: Infrastructure and observability as code
- Splunk Education: Using the Splunk Observability Cloud Terraform provider
- Splunk Education: Managing Splunk Observability Cloud teams as code
- Terraform: Terraform documentation
- Terraform: Splunk Observability Cloud provider