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.

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.

  1. Run the following command to create a directory.

    mkdir learn-monaco-auto-tag
  2. Change to the new directory.

    cd learn-monaco-auto-tag
  3. Create a project directory to store the tagging configuration and change to it.

    mkdir -p project-example/auto-tag
    cd project-example/auto-tag
  4. 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.
  5. 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
    }
    }
    ]
    }
  6. 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"
  7. Change back to the configuration directory folder (learn-monaco-auto-tag).

    cd ../..
  8. Create a deployment manifest file to instruct the Dynatrace Monaco CLI which project to deploy and where to deploy it.

    touch manifest.yaml
  9. 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"
  10. Export your Dynatrace token to your environment. Make sure that your token has the permissions listed in the prerequisites.

    export devToken=YourTokenValue
  11. Run monaco deploy --dry-run to ensure your configuration is syntactically valid and consistent.

    monaco deploy --dry-run manifest.yaml
  12. 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

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.

  1. To apply your configuration with the monaco deploy command, provide the name of the deployment file as an argument.

    monaco deploy manifest.yaml
  2. 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 verify that your tag has been created

  1. Go to Settings and select Tags > Automatically applied tags.
  2. 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.

  1. To delete the previously created tag DTServer, create a file called delete.yaml in the root folder.

    touch delete.yaml
  2. Open the file in your text editor and paste the following configuration, then save the changes.

    delete:
    - type: auto-tag
    name: "DTServer"
  3. 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
  4. 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.