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.
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.
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.
Export your Dynatrace token to your environment. Make sure that your token has the permissions listed in the prerequisites.
exportdevToken=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.
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
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 called delete.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.
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 called delete.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.