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.
1mkdir learn-monaco-auto-tag -
Change to the new directory.
1cd learn-monaco-auto-tag -
Create a project directory to store the tagging configuration and change to it.
1mkdir -p project-example/auto-tag1cd project-example/auto-tag -
Create these two files:
1touch 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.
1{2 "name": "{{ .name }}",3 "rules": [4 {5 "enabled": true,6 "valueNormalization": "Leave text as-is",7 "type": "ME",8 "attributeRule": {9 "entityType": "PROCESS_GROUP",10 "conditions": [11 {12 "key": "PROCESS_GROUP_PREDEFINED_METADATA",13 "dynamicKey": "DYNATRACE_CLUSTER_ID",14 "operator": "BEGINS_WITH",15 "stringValue": "Server on Cluster",16 "caseSensitive": true17 }18 ],19 "pgToHostPropagation": true,20 "pgToServicePropagation": true21 }22 }23 ]24} -
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
.1configs:2- id: application-tagging3 type:4 settings:5 schema: builtin:tags.auto-tagging6 scope: environment7 config:8 template: "auto-tag.json"9 name: "DTServer" -
Change back to the configuration directory folder (
learn-monaco-auto-tag
).1cd ../.. -
Create a deployment manifest file to instruct the Dynatrace Monaco CLI which project to deploy and where to deploy it.
1touch 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.1manifestVersion: 1.02projects:3 - name: auto-tag4 path: project-example56environmentGroups:7 - name: development8 environments:9 - name: development-environment10 url:11 value: "https://<your-dynatrace-environment>.live.dynatrace.com"12 auth:13 token:14 name: "devToken" -
Export your Dynatrace token to your environment. Make sure that your token has the permissions listed in the prerequisites.
1export devToken=YourTokenValue -
Run
monaco deploy --dry-run
to ensure your configuration is syntactically valid and consistent.1monaco deploy --dry-run manifest.yaml -
If the dry run was successful, the Dynatrace Monaco CLI will return the following message.
12023-08-24T10:21:07+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[]22023-08-24T10:21:07+02:00 info Loading 1 projects...32023-08-24T10:21:08+02:00 info Projects to be deployed (1):42023-08-24T10:21:08+02:00 info - auto-tag52023-08-24T10:21:08+02:00 info Environments to deploy to (1):62023-08-24T10:21:08+02:00 info - development-environment72023-08-24T10:21:08+02:00 info Validating configurations for environment `development-environment`...82023-08-24T10:21:08+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config92023-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.1monaco deploy manifest.yaml -
If the deployment is successful, Dynatrace Configuration as Code CLI will return the following message:
12023-08-24T10:21:13+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[]22023-08-24T10:21:13+02:00 info Loading 1 projects...32023-08-24T10:21:13+02:00 info Projects to be deployed (1):42023-08-24T10:21:13+02:00 info - auto-tag52023-08-24T10:21:13+02:00 info Environments to deploy to (1):62023-08-24T10:21:13+02:00 info - development-environment72023-08-24T10:21:13+02:00 info Deploying configurations to environment `development-environment`...82023-08-24T10:21:13+02:00 info [coord=auto-tag:builtin:tags.auto-tagging:application-tagging] Deploying config92023-08-24T10:21:14+02:00 info Deployment finished without errorsIf 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.1touch delete.yaml -
Open the file in your text editor and paste the following configuration, then save the changes.
1delete:2- project: "auto-tag"3 type: auto-tag4 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.1monaco delete --manifest manifest.yaml --file delete.yaml -e development-environment -
If the deletion is successful,
monaco
returns the following message:12023-08-24T10:10:37+02:00 info Loading manifest "{your full path to the file}/manifest.yaml". Restrictions: groups=[], environments=[]22023-08-24T10:10:39+02:00 info Deleting configs for environment `development-environment`...32023-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