Deploy your first configuration
To get you started with managing configurations, this section will guide you through a simple example: creating a tagging rule with Dynatrace Configuration as Code via Monaco. You will learn how to create, deploy, and delete a configuration.
Prerequisites
-
The latest version of Dynatrace Configuration as Code via Monaco (the Dynatrace Monaco CLI) installed (see Install Dynatrace Configuration as Code via Monaco) and available on your
PATH
. -
A Dynatrace environment and access to create environment tokens.
-
A Dynatrace token with at least the following permissions:
- Access problem and event feed, metrics, and topology (
DataExport
)- Required for querying general information about your environment.
- Read configuration (
ReadConfig
)- Required for reading existing auto-tags.
- Write configuration (
WriteConfig
)- Required for creating your auto-tag.
- Read settings (
settings.read
) (API v2)- Required for reading settings configuration.
- Write settings (
settings.write
) (API v2)- Required for modifying settings configuration.
- Access problem and event feed, metrics, and topology (
To learn how to create tokens, see Create an API token.
Reference project
If you're stuck at any point while following this guide, you can find a finished version of the project on GitHub.
Create configuration
You can create a tagging rule in an environment that will apply tags to hosts and services where a Dynatrace server is detected.
-
Run the following command to create a directory.
mkdir learn-monaco-auto-tag
-
Change to the new directory.
cd learn-monaco-auto-tag
-
Create a project directory to store the tagging configuration and change to it.
mkdir -p project-example/auto-tag
cd project-example/auto-tag
-
Create these two files:
touch auto-tag.json auto-tag.yaml
- The
auto-tag.json
will store the JSON configuration of the tagging configuration. - The
auto-tag.yaml
will be the YAML configuration file which will list the configurations to be deployed.
- The
-
Open the
auto-tag.json
configuration file in your text editor, paste the configuration below and save the file.The name used in this configuration is specified as a variable and its value will be given in the YAML configuration.
{ "name": "{{ .name }}", "rules": [ { "enabled": true, "valueNormalization": "Leave text as-is", "type": "ME", "attributeRule": { "entityType": "PROCESS_GROUP", "conditions": [ { "key": "PROCESS_GROUP_PREDEFINED_METADATA", "dynamicKey": "DYNATRACE_CLUSTER_ID", "operator": "BEGINS_WITH", "stringValue": "Server on Cluster", "caseSensitive": true } ], "pgToHostPropagation": true, "pgToServicePropagation": true } } ] }
-
Open the
auto-tag.yaml
configuration file in your text editor, paste the configuration below and save the file.The name of the tag should be provided here. In this example:
DTServer
.configs: - id: application-tagging type: settings: schema: builtin:tags.auto-tagging scope: environment config: template: "auto-tag.json" name: "DTServer"
-
Change back to the configuration directory folder (
learn-monaco-auto-tag
).cd ../..
-
Create a deployment manifest file to instruct the Dynatrace Monaco CLI which project to deploy and where to deploy it.
touch manifest.yaml
-
Open the deployment manifest file (
manifest.yaml
) in your text editor, paste in the configuration below, replace the URL value with your environment URL, and save the file.manifestVersion: 1.0 projects: - name: auto-tag path: project-example environmentGroups: - name: development environments: - name: development-environment url: value: "https://<your-dynatrace-environment>.live.dynatrace.com" auth: token: name: "devToken"
-
Export your Dynatrace token to your environment. Make sure that your token has the permissions listed in the prerequisites.
export devToken=YourTokenValue
-
Run
monaco deploy --dry-run
to ensure your configuration is syntactically valid and consistent.monaco deploy --dry-run manifest.yaml
-
If the dry run was successful, the Dynatrace Monaco CLI will return the following message.
2023-08-24T10:21:07+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[] 2023-08-24T10:21:07+02:00 info Loading 1 projects... 2023-08-24T10:21:08+02:00 info Projects to be deployed (1): 2023-08-24T10:21:08+02:00 info - auto-tag 2023-08-24T10:21:08+02:00 info Environments to deploy to (1): 2023-08-24T10:21:08+02:00 info - development-environment 2023-08-24T10:21:08+02:00 info Validating configurations for environment `development-environment`... 2023-08-24T10:21:08+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config 2023-08-24T10:21:08+02:00 info Validation finished without errors
-
Open Windows PowerShell.
-
Create a directory for your configuration.
mkdir learn-monaco-auto-tag
-
Change to the new directory.
cd learn-monaco-auto-tag
-
Create a project directory to store the tagging configuration and change to it.
mkdir -p project-example/auto-tag
cd project-example/auto-tag
-
Create two files.
- The first file (auto-tag.json) stores the JSON configuration of the tagging configuration.
- The second file (auto-tag.yaml) will be the YAML configuration file which lists the configurations to be deployed.
New-Item auto-tag.json New-Item auto-tag.yaml
-
Open the JSON configuration file (
auto-tag.json
) in your text editor and paste in the configuration below. Save the file.The name used in this configuration is specified as a variable and its value will be given in the YAML configuration.
{ "name": "{{ .name }}", "rules": [ { "enabled": true, "valueNormalization": "Leave text as-is", "type": "ME", "attributeRule": { "entityType": "PROCESS_GROUP", "conditions": [ { "key": "PROCESS_GROUP_PREDEFINED_METADATA", "dynamicKey": "DYNATRACE_CLUSTER_ID", "operator": "BEGINS_WITH", "stringValue": "Server on Cluster", "caseSensitive": true } ], "pgToHostPropagation": true, "pgToServicePropagation": true } } ] }
-
Open the YAML configuration file (
auto-tag.yaml
) in your text editor and paste the configuration below. Save the file.The name of the tag should be provided here. In this example:
DTServer
.configs: - id: application-tagging type: settings: schema: builtin:tags.auto-tagging scope: environment config: template: "auto-tag.json" name: "DTServer"
-
Change back to the configuration directory folder (
learn-monaco-auto-tag
).cd ../..
-
Create a deployment manifest file to instruct the Dynatrace Monaco CLI which project to deploy and where to deploy it.
New-Item manifest.yaml
-
Open the deployment manifest file (
manifest.yaml
) in your text editor, paste in the configuration below and replace the URL value with your environment URL. Save the file.manifestVersion: 1.0 projects: - name: auto-tag path: project-example environmentGroups: - name: development environments: - name: development-environment url: value: "https://<your-dynatrace-environment>.live.dynatrace.com" auth: token: name: "devToken"
-
Export your Dynatrace token to your environment. Make sure that your token has the permissions listed in the prerequisites.
$env:devToken="YourTokenValue"
-
Run
monaco deploy --dry-run
to ensure your configuration is syntactically valid and consistent.monaco deploy --dry-run manifest.yaml
-
If the dry run is successful,
monaco
returns the following message:2023-08-24T10:21:07+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[] 2023-08-24T10:21:07+02:00 info Loading 1 projects... 2023-08-24T10:21:08+02:00 info Projects to be deployed (1): 2023-08-24T10:21:08+02:00 info - auto-tag 2023-08-24T10:21:08+02:00 info Environments to deploy to (1): 2023-08-24T10:21:08+02:00 info - development-environment 2023-08-24T10:21:08+02:00 info Validating configurations for environment `development-environment`... 2023-08-24T10:21:08+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config 2023-08-24T10:21:08+02:00 info Validation finished without errors
Deploy configuration
Now that you have created the configuration you need to deploy it to your Dynatrace environment. To do this, you use the monaco deploy
command.
-
To apply your configuration with the
monaco deploy
command, provide the name of the deployment file as an argument.monaco deploy manifest.yaml
-
If the deployment is successful, Dynatrace Configuration as Code CLI will return the following message:
2023-08-24T10:21:13+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[] 2023-08-24T10:21:13+02:00 info Loading 1 projects... 2023-08-24T10:21:13+02:00 info Projects to be deployed (1): 2023-08-24T10:21:13+02:00 info - auto-tag 2023-08-24T10:21:13+02:00 info Environments to deploy to (1): 2023-08-24T10:21:13+02:00 info - development-environment 2023-08-24T10:21:13+02:00 info Deploying configurations to environment `development-environment`... 2023-08-24T10:21:13+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config 2023-08-24T10:21:14+02:00 info Deployment finished without errors
If your configuration fails to deploy, refer to the output error description. You may have syntax errors in your files or your token requires more permissions.
-
To apply your configuration with the
monaco deploy
command, provide the name of the deployment file as argument.monaco deploy manifest.yaml
-
If the deployment is successful,
monaco
returns the following message:2023-08-24T10:21:13+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[] 2023-08-24T10:21:13+02:00 info Loading 1 projects... 2023-08-24T10:21:13+02:00 info Projects to be deployed (1): 2023-08-24T10:21:13+02:00 info - auto-tag 2023-08-24T10:21:13+02:00 info Environments to deploy to (1): 2023-08-24T10:21:13+02:00 info - development-environment 2023-08-24T10:21:13+02:00 info Deploying configurations to environment `development-environment`... 2023-08-24T10:21:13+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config 2023-08-24T10:21:14+02:00 info Deployment finished without errors
If your configuration fails to deploy, refer to the output error description. You may have syntax errors in your files or your token requires more permissions.
To verify that your tag has been created
- In the Dynatrace menu, go to Settings and select Tags > Automatically applied tags.
- Search for
DTServer
.
Delete configuration
Now that your configuration is deployed, you can delete it. To do this, you will use the monaco delete
command.
-
To delete the previously created tag
DTServer
, create a file calleddelete.yaml
in the root folder.touch delete.yaml
-
Open the file in your text editor and paste the following configuration, then save the changes.
delete: - project: "auto-tag" type: auto-tag name: "DTServer"
-
Delete the tag from your environment. The
delete
command requires both the delete file and the deployment manifest file as arguments. The deployment manifest file indicates in which environments to delete the configuration specified in the delete file.monaco delete --manifest manifest.yaml --file delete.yaml -e development-environment
-
If the deletion is successful,
monaco
returns the following message:2023-08-24T10:10:37+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[] 2023-08-24T10:10:39+02:00 info Deleting configs for environment `development-environment`... 2023-08-24T10:10:39+02:00 info Deleting configs of type auto-tag...
-
To delete the previously created tag
DTServer
, create a file calleddelete.yaml
in the root folder.New-Item delete.yaml
-
Open the file in your text editor and paste the following configuration, then save the changes.
delete: - project: "auto-tag" type: auto-tag name: "DTServer"
-
Delete the tag from your environment. The
delete
command requires both the delete file and the deployment manifest file as arguments. The deployment manifest file indicates in which environments to delete the configuration specified in the delete file.monaco delete --manifest manifest.yaml --file delete.yaml -e development-environment
-
If the deletion is successful,
monaco
returns the following message:2023-08-24T10:10:37+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[] 2023-08-24T10:10:39+02:00 info Deleting configs for environment `development-environment`... 2023-08-24T10:10:39+02:00 info Deleting configs of type auto-tag...
What's next
Now that you know the basics of creating, deploying, and deleting a configuration, you're ready to learn more.
- For configuration management details, see Dynatrace Configuration as Code via Monaco
- For a command cheat sheet, see Dynatrace Monaco CLI command reference
- For more Dynatrace Monaco CLI examples, go to GitHub