In addition to the out-of-the-box functionality of Terraform, the provider has the ability to be executed as a standalone executable to export an existing configuration from a Dynatrace environment. This functionality provides an alternative to manually creating a Terraform configuration and provides an easy way to create templates based on an existing configuration.
Terraform CLI with the Dynatrace provider installed and available under
Access token with at least the following permissions:
- Read settings (
- Write settings (
- Read configuration (
- Write configuration (
- Create and read synthetic monitors, locations, and nodes (
- Capture request data (
- Read credential vault entries (
- Write credential vault entries (
- Read network zones (
- Write network zones (
- Read settings (
Define the environment URL and API token in a terminal window. This identifies the Dynatrace tenant for configuration retrieval.bash
set DYNATRACE_ENV_URL=https://########.live.dynatrace.com set DYNATRACE_API_TOKEN=dt0c01.########.########bash
set DYNATRACE_ENV_URL=https://<dynatrace-host>/e/######## set DYNATRACE_API_TOKEN=dt0c01.########.########
DYNATRACE_TARGET_FOLDERto designate an output directory. If not set, the default
Go to the Terraform Dynatrace Provider executable in the terminal. This isn't the generic
terraform.exefile. Typically, it's found in
Directly invoke the executable with any needed options. For examples, see the Usage examples section below.
terraform-provider-dynatrace.exe -export [-ref] [-migrate] [-id] [-flat] [-exclude] [<resourcename>[=<id>]]
./terraform-provider-dynatrace -export [-ref] [-migrate] [-import-state-v2] [-id] [-flat] [-exclude] [<resourcename>[=<id>]]
-ref: Enable resources with data sources and dependencies.
-migrate: Enable resources with dependencies, excluding data sources. See more in the Migration guide (LINK).
-import-state-v2: Initialize terraform modules and import resources into the state.
-id: Display commented id output in resource files.
-flat: Store all resources directly within the target folder without a module structure.
-exclude: Exclude specified resources from export.
By default, dashboards (
dynatrace_json_dashboard) are excluded from the export. Specify them directly in the command line to retrieve.
The following examples demonstrate various ways to use the export utility.
- Export all configurations without data sources/dependencies:
- Export all configurations with data sources/dependencies and include commented IDs:
./terraform-provider-dynatrace -export -ref -id
- Export specific configurations and their dependencies:
./terraform-provider-dynatrace -export -ref dynatrace_json_dashboard dynatrace_web_application
- Export specific alerting profiles by their IDs:
./terraform-provider-dynatrace -export -ref dynatrace_alerting=4f5942d4-3450-40a8-818f-c5faeb3563d0 dynatrace_alerting=9c4b75f1-9a64-4b44-a8e4-149154fd5325
- Export multiple resources including dependencies:
./terraform-provider-dynatrace -export -ref dynatrace_calculated_service_metric dynatrace_alerting=4f5942d4-3450-40a8-818f-c5faeb3563d0
- Export all configurations and import them into the state:
./terraform-provider-dynatrace -export -import-state-v2
- Export specific web applications and import them into the state:
./terraform-provider-dynatrace -export -import-state-v2 dynatrace_web_application
- Export all configurations except specified resources:
./terraform-provider-dynatrace -export -ref -exclude dynatrace_calculated_service_metric dynatrace_alerting
Some exported configurations might be deprecated or require modifications. Such files are moved to the
.flaweddirectory in the output folder, with reasons provided as comments at the beginning of the file.
Some configurations might lack essential information for a
terraform applydue to sensitive data or instances where the files require additional attention. These files are moved to
.requires_attention, with explanations provided as comments at the beginning of the file.
dynatrace_credentialsconfidential strings are not available via the API.