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 PATH
.
Access token with at least the following permissions:
settings.read
)settings.write
)ReadConfig
)WriteConfig
)ExternalSyntheticIntegration
)CaptureRequestData
)credentialVault.read
)credentialVault.write
)networkZones.read
)networkZones.write
)Certain resources require an OAuth client for authentication (for example, automation, document, and account management APIs). For details, see the resource-specific pages in the Terraform Registry.
Define the environment URL and API token in a terminal window. This identifies the Dynatrace tenant for configuration retrieval.
Windows
Linux
Optionally, set DYNATRACE_TARGET_FOLDER
to designate an output directory. If not set, the default ./configuration
is used.
Go to the Terraform Dynatrace Provider executable in the terminal. This isn't the generic executable, such as terraform.exe
or ./terraform
. Typically, it's found in .terraform/providers/registry.terraform.io/dynatrace-oss/dynatrace/{provider_version}/{os_version}/terraform-provider-dynatrace_x.y.z
.
Directly invoke the executable with any needed options. Because export is additional functionality, it's OK to invoke the plugin directly, and the warning can be safely ignored. For examples, see the Usage examples section below.
Windows: terraform-provider-dynatrace.exe -export [-ref] [-migrate] [-import-state] [-id] [-flat] [-exclude] [<resourcename>[=<id>]]
Linux: ./terraform-provider-dynatrace -export [-ref] [-migrate] [-import-state] [-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.
-import-state
: 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.
-list-exclusions
: Prints an overview of resources that will not get exported unless explicitly specified.
By default, dashboards (dynatrace_json_dashboard
) and various other resources are excluded from the export unless the resource is directly specified. Use the option -list-exclusions
for a full list of the excluded resources.
The following examples demonstrate various ways to use the export utility.
./terraform-provider-dynatrace -export
./terraform-provider-dynatrace -export -ref -id
./terraform-provider-dynatrace -export -ref * dynatrace_json_dashboard dynatrace_document
./terraform-provider-dynatrace -export dynatrace_json_dashboard dynatrace_document
./terraform-provider-dynatrace -export -ref dynatrace_json_dashboard dynatrace_web_application
./terraform-provider-dynatrace -export -ref dynatrace_alerting=4f5942d4-3450-40a8-818f-c5faeb3563d0 dynatrace_alerting=9c4b75f1-9a64-4b44-a8e4-149154fd5325
./terraform-provider-dynatrace -export -ref dynatrace_calculated_service_metric dynatrace_alerting=4f5942d4-3450-40a8-818f-c5faeb3563d0
./terraform-provider-dynatrace -export -import-state
./terraform-provider-dynatrace -export -import-state dynatrace_web_application
./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 .flawed
directory in the output folder, with reasons provided as comments at the beginning of the file.
Some configurations might lack essential information for a terraform apply
due 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.
For example, dynatrace_credentials
confidential strings are not available via the API.