The integration of Dynatrace monitoring with Terraform enables teams to define, version, and replicate monitoring configuration through declarative infrastructure as code. Dynatrace offers a dedicated Terraform provider to manage your monitoring environment. Terraform, by HashiCorp, is a widely adopted Infrastructure-as-Code tool. The Dynatrace Terraform provider is a library that allows you to use the Terraform syntax and functionalities to create a custom configuration resource, such as a Dynatrace dashboard, workflow, or custom alert. Additionally, it provides data sources such as the entity ID of a service detected by Dynatrace. The Dynatrace Terraform provider allows you to pull information from these data sources into Dynatrace.
This article covers the provider architecture, installation and configuration, resource management, project structure patterns, and operational workflows for automating Dynatrace as code.
Provider Overview and Support
The Dynatrace Terraform Provider enables you to manage Dynatrace resources using Terraform, an open-source infrastructure as code software tool. This allows for automated and consistent deployments of monitoring configurations in Dynatrace.
The Dynatrace Terraform Provider is officially supported by Dynatrace.
Terraform 0.13.x+
The Dynatrace Terraform Provider is provided by Dynatrace Incorporated.
Support is provided by the Dynatrace Support team, as described on the support page.
Please use the Dynatrace Community to let us know any Product Ideas, as well as for general discussion and questions.
Additional information can be found under Dynatrace Configuration as Code via Terraform.
The provider is also available as a standalone executable. In addition to acting as a Terraform Provider Plugin the executable terraform-provider-dynatrace
terraform-provider-dynatrace.exe
on Windows can also get directly invoked. The utility then reaches out to the Dynatrace Environment specified by the command line arguments and fetches all currently supported configuration items.
Please check the documentation within the Terraform Registry for how to use and configure this Provider as well as for currently supported resources and data sources.
Prerequisites and Installation
Before you start, ensure you have the following:
- Terraform installed on your machine. You can download it from Terraform Downloads.
- A Dynatrace account with API access.
- Basic understanding of Terraform and its configuration files.
This guide describes how to install the Terraform CLI and set up the Dynatrace Terraform Provider.
Start by installing Terraform on your system as described in the Terraform documentation.
Download the binary according to your operating system.
Set the PATH
to ensure the Terraform binary is accessible system-wide.
Verify the setup by opening a new terminal session and running the following command:
terraform version
The Dynatrace Provider is available in the Terraform Registry and can be fetched automatically during the terraform init process.
Create a working directory for your Terraform configuration files.
Within this directory, create a providers.tf file
To use the Dynatrace Terraform Provider, you need to install it. Here’s how you can do it:
- Create a directory for your Terraform configuration.
- Inside this directory, create a file named main.tf.
- Add the following code to the main.tf file:
provider "dynatrace" {
api_url = "https://YOUR_DYNATRACE_TENANT_ID.live.dynatrace.com/api"
token = "YOUR_API_TOKEN"
}
- Replace YOURDYNATRACETENANTID and YOURAPI_TOKEN with your actual Dynatrace tenant ID and API token.
Provider Configuration
With the provider set up, you can now manage various Dynatrace resources
By using Terraform, you can automate the setup and configuration of your monitoring environment, enabling quicker deployments and consistent configurations.
The provider block is the entry point for authentication and tenant targeting. Configuration is typically expressed in providers.tf or main.tf.
provider "dynatrace" {
api_url = "https://YOUR_DYNATRACE_TENANT_ID.live.dynatrace.com/api"
token = "YOUR_API_TOKEN"
}
Environment variables for troubleshooting are described here.
A common configuration table is as follows:
| Configuration Element | Purpose |
| api_url | Dynatrace tenant base URL for API calls |
| token | API token for authentication |
| provider block | Declares Dynatrace provider usage in Terraform |
Resources and Data Sources
The Dynatrace Terraform provider is a library that allows you to use the Terraform syntax and functionalities to create a custom configuration resource, such as a Dynatrace dashboard, workflow, or custom alert.
Additionally, it provides data sources such as the entity ID of a service detected by Dynatrace. The Dynatrace Terraform provider allows you to pull information from these data sources into Dynatrace.
Managing configurations in Dynatrace across multiple environments can be challenging without automation. Terraform provides a powerful way to define, manage, and scale Dynatrace configurations as code, reducing manual effort and ensuring consistency.
In practice, the provider supports configuration categories such as:
- Custom Attributes
- Synthetic Monitoring
- Maintenance Windows
- Dashboards
- Workflows
- Custom Alerts
Resource and data source support is documented in the Terraform Registry.
Why Use Terraform with Dynatrace
Benefits of using Terraform for Dynatrace automation include:
- Consistency: Configuration-as-code eliminates manual setup discrepancies.
- Scalability: Easily manage configurations across environments or teams.
- Automation: Apply, update, and destroy configurations seamlessly.
For more information, refer to the official Dynatrace Terraform Provider Documentation.
The approach ensures:
- Consistency across environments.
- Easier scalability and management.
- Collaboration via version control.
Project Structure
Before diving into the code, let’s look at the structure of our project
A typical Dynatrace Terraform project separates provider configuration, modules, and environment-specific variables.
project-root/
- providers.tf
- main.tf
- variables.tf
- modules/
- dashboards/
- alerts/
- synthetic/
Scaling the Approach
The same principles can be applied to Custom Attributes and Maintenance Windows, following a similar structure:
- Define reusable modules.
- Use JSON files for resource definitions.
- Pass configurations dynamically to modules.
This structure supports reuse across dev, staging, and production tenants and enables peer review through version control.
Workflow Plan and Apply
Standard Terraform lifecycle applies to Dynatrace.
Plan Changes:
terraform plan
This shows the changes Terraform will make in Dynatrace.
Apply Changes:
terraform apply
Confirm the changes to apply them.
The workflow enables safe review of monitoring changes before they are pushed to the Dynatrace environment.
A typical operational table is as follows:
| Command | Effect |
| terraform init | Fetches Dynatrace Provider from Registry |
| terraform plan | Previews configuration drift |
| terraform apply | Creates updates configuration in Dynatrace |
| terraform destroy | Removes managed resources |
Configuration as Code Patterns
Automating Dynatrace Configuration with Terraform
Managing configurations in Dynatrace across multiple environments can be challenging without automation. Terraform provides a powerful way to define, manage, and scale Dynatrace configurations as code, reducing manual effort and ensuring consistency. In this guide, we’ll cover how to structure a Terraform project to automate the management of Custom Attributes, Synthetic Monitoring, and Maintenance Windows.
By adopting Terraform for Dynatrace, you unlock the benefits of Infrastructure as Code (IaC). This approach ensures:
- Consistency across environments.
- Easier scalability and management.
- Collaboration via version control.
Start small with a single module and gradually scale your configuration to include all Dynatrace resources. Happy automating!
Conclusion
The Dynatrace Terraform provider bridges monitoring configuration with infrastructure as code practices. By treating dashboards, workflows, alerts, synthetic monitors, maintenance windows, and custom attributes as declarative resources, teams achieve repeatable deployments, reduced manual error, and auditable change history.
The provider is officially supported by Dynatrace Incorporated, requires Terraform 0.13.x+, and is delivered through the Terraform Registry with automatic fetching during terraform init. Authentication is handled via api_url and token in the provider block, with environment variable support for troubleshooting.
Operational maturity comes from modular project structure, reusable modules, JSON-driven resource definitions, and dynamic variable passing. The standard plan and apply cycle gives visibility into changes before they reach production Dynatrace tenants.
When combined with version control and peer review, Configuration as Code for Dynatrace delivers consistency across environments, scalability across teams, and automation from definition through destruction. The practice is particularly valuable for organizations standardizing monitoring across multiple Dynatrace tenants and aligning observability configuration with broader infrastructure pipelines.