YAML configuration
Each configuration YAML file contains a list of configurations to be deployed.
A basic configuration YAML file looks like this:
configs:
- id: test-dashboard
type:
api: dashboard
config:
name: Test Dashboard
template: dashboard.json
parameters:
owner: Test User
As you can see, the top-level element is configs
. Its value is a list of configurations. Each configuration requires the following fields: id
, type
, and config
.
It's also possible to override values from config
on the environment and environment-group level. For this, there exist the optional groupOverrides
and environmentOverrides
fields.
ID
The id
field identifies a config within the configurations. It has to be unique for the same configType and project. So it's possible to have, for example, two dashboards with the same id
in two different projects. Note that the field is only local to Dynatrace Configuration as Code. It has nothing to do with the ID provided by the Dynatrace API. One important use case for this id
is when using reference parameters.
Type
The type
field defines the type of the Dynatrace configuration.
A type
can be one of the supported Configuration API types or a Setting.
Type - API
An API type
can be defined as:
type:
api: dashboard
or in shorthand form as:
type: dashboard
See the list of supported configuration types for all possible api
values.
Type - Setting
Settings are defined by their schema
, scope
, and an optional schemaVersion
.
A Settings type
can be defined as:
type:
settings:
schema: builtin:tags.auto-tagging
scope: environment
The scope
can be defined as a value, reference, or environment parameter.
In the sample above, it's defined as a shorthand value.
Because many settings are made in the scope of a Dynatrace entity, referencing another configuration's ID is a useful way of configuring entities after they've been created via Dynatrace Configuration as Code.
In the sample below, a web application is configured, and then settings for this application are made.
configs:
- id: MyApp
type:
api: application-web
config:
name: My Sample Web Application
template: application.json
- id: MyApp_RUMSettings
type:
settings:
schema: builtin:rum.web.enablement
scope:
type: reference
configType: application-web
configId: MyApp
property: id
config:
name: MyApp_RUMSettings
template: rum-settings.json
As you can see, the scope
of the rum.web.enablement
setting is a reference to the web application.
A Settings type
can also contain a field called originObjectId
which is the Dynatrace object id of a downloaded Settings 2.0 object and is used to tell whether a
particular Settings 2.0 object already exists on an environment (for example, the same environment it was pulled from) or not. Note that originObjectId
is optional, meaning that
as a user, you don't need to care about it unless you want to match a non-downloaded Settings 2.0 object to a specific existing one:
type:
settings:
schema: builtin:tags.auto-tagging
scope: environment
originObjectId: vu9U3hXa3q0AAAABABxidWlsdGluOmFwaXMuZGV0ZWN0aW9uLXJ1bGVzAAZ0ZW5hbnQABnRlbmFudAAkYzU0NzVjNGUtZTE1Zi0zY2JhLWFlYjAtNzk5OTlmYzdjNjNjvu9U3hXa3q0
Config
The config
field offers the following fields:
name
—Name used to identify objects in the Dynatrace APItemplate
—Defines templating file used to render the request to the Dynatrace API (for details, see Manage Configuration as Code project)- optional
skip
—If set totrue
, the Configuration as Code CLI will not deploy this configuration - optional
parameters
—List of parameters available in the template
Name
The name
is used to identify configurations on a Dynatrace environment and ensure that they are updated when they already exist.
For this, the name
needs to be used in the JSON template to fill the specific name property of the configuration. Usually, this is also just name
, but for some configurations, this may differ; see the special cases described for JSON templates and refer to the API documentation if in doubt.
When downloading, names are automatically extracted and placed in the YAML for you.
When referencing the name
in a JSON template, it needs to be used as is, with no additional text or characters around it.
The name property in JSON should always be used like this:
"{{ .name }}"
If you encounter issues with configurations not being created several times instead of updated, check to make sure that your reference to the name does not contain any accidental spaces or other characters that make what is sent to Dynatrace in the JSON different from the name defined in the YAML.
Parameters
Parameters are used to provide values in configuration templates. They are defined as YAML objects with a type
entry. This type
then further decides how the parameter object is interpreted. One important property of parameters is that they are lazy: the value of a parameter is only evaluated if it's referenced by a configuration that is going to be deployed.
The following parameter types are available:
Value
The value parameter is the simplest form of a parameter. Besides the type
property, it also requires the value
property. You can define whatever you like as the value, even nested maps. This value is then accessible in the template file.
Because value
parameters are the most common parameter type, there is a special short-form syntax to define them: you can simply provide the value if your parameter is neither an array nor a map.
For example:
parameters:
threshold: 15
complexThreshold:
type: value
value:
amount: 15
unit: sec
In the template of this config, you could then access the threshold
parameter via { .threshold }
. To access, for example, the amount
of the complexThreshold
, you could use { .complexThreshold.amount }
.
Environment
Parameters of type environment
allow you to reference an environment variable. The name of the environment variable to reference is defined via a name
property.
-
You can provide a default value (via the
default
property) for cases in which the environment variable is not present. -
If the
default
property is not set and the env variable is missing, the parameter cannot be resolved. This will fail the deployment.Note this is the case only if the parameter is relevant to be deployed. Parameters not referenced by the config to deploy are not evaluated.
Example:
parameters:
owner:
type: environment
name: OWNER
default: "-"
target:
type: environment
name: TARGET
In the above example:
- The
owner
parameter will evaluate to the value of theOWNER
environment variable. If the environment variable is not present, it will evaluate to value-
. - The
target
parameter will evaluate to the value of theTARGET
environment variable. It will fail the deployment if the variable is not set at deployment time.
Reference
Because it's often necessary to reference a property of another configuration, Monaco offers a special reference parameter. This parameter allows one configuration to depend on almost any parameter of another config.
To achieve this, a parameter of type reference
defines project
, configType
,configId
, and property
properties to tell Monaco where to get its value.
parameters:
mz_id:
type: reference
project: project-1
configType: management-zone
configId: main
property: id
In the sample above, the value of mz_id
will be the Dynatrace object ID of the configuration of type management-zone
with ID main
from the project-1
project.
The property
can be any parameter of the target config, or one of the special properties name
or id
.
The id
property will be the ID of the referenced Dynatrace object on the targeted environment.
For example, this allows you to create a Web Application and reference its Monitored Entity ID in a Synthetic Test.
Dynatrace Configuration as Code will make sure that the deployment of configuration is ordered and that the dependent config is deployed first.
If you configure a cycle of dependencies, the deployment will fail with an error.
Short notation
Because reference
parameters are one of the most common parameter types, there is a special short-form syntax to define them as an array:
- Syntax:
[ "{project}", "{configType}", "{configId}", "{property}" ]
- Example:
mz_id: ["project-1", "management-zone", "main", "id"]
Note that in this case, no type
is needed, as the type is inferred based on the syntax.
Partial references
It's possible to omit some reference fields. In this case, they will be filled with the same value as the current config.
Generally, you might want to use this for simplicities sake when referencing configuration within the same project
- simply omit the field.
parameters:
mz_id:
type: reference
configType: management-zone
configId: main
property: id
While it's possible to omit configType
and even configId
, note that you can only leave the upper-most level empty and can't leave a gap.
So if configType
is omitted, so must project
.
Below you find a full sample (using shorthand references):
-
infrastructure/management-zone/config.yaml
configs: - id: main type: api: management-zone config: name: "Main zone" template: "zone.json"
-
development/management-zone/config.yaml
configs: - id: development type: api: management-zone config: name: "Development zone" template: "zone.json"
-
development/dashboard/config.yaml
configs: - id: a_dashboard type: api: dashboard config: name: "Overview dashboard" template: "dashboard.json" - id: overview type: api: dashboard config: name: "Overview dashboard" template: "dashboard.json" parameters: zoneId: ["infrastructure", "management-zone", "main", "id"] devZoneId: ["management-zone", "development", "id"] # inferred project 'development' otherDashboard: ["a_dashboard", "id"] # inferred project 'development' and type 'dashboard'
Compound
The compound parameter is a parameter composed of other parameters of the same config. This parameter requires two properties:
- A
format
string - A list of
references
to all referenced parameters.
The format
string can be any string. To use parameters in it, use the syntax {{ .parameter }}
, where parameter
is the name of the parameter to be filled in.
For example:
parameters:
example:
type: compound
format: "{{ .greeting }} {{ .entity }}!"
references:
- greeting
- entity
greeting: "Hello"
entity: "World"
This would produce the value Hello World!
for example
. Compound parameters can also be used for more complex values, such as in the following example:
parameters:
example:
type: compound
format: "{{ .resource.name }}: {{ .resource.percent }}%"
references:
- resource
progress:
type: value
value:
name: "Health"
percent: 40
This would produce the value Health: 40%
, for example.
Even though referenced parameters can only be from the same config, by using the reference parameter, it's possible to make a compound parameter with other configs. This is also true for environment variables.
parameters:
example:
type: compound
format: "{{ .user }}'s dashboard is {{ .status }}"
references:
- user
- status
user:
type: environment
name: USER_NAME
status:
type: reference
configType: dashboard
configId: dashboard
property: status
List
Parameters of type list
allow you to define lists of value parameters. When written into a template, these are written as a JSON list surrounded by square brackets and separated by commas.
This type of parameter is generally useful when you require a simple list of things, such as emails or identifiers, that can be filled with any kind of value parameter.
For example:
parameters:
recipients:
type: list
values:
- first.last@company.com
- someone.else@company.com
geolocations:
type: list
values: ["GEOLOCATION-1234567", "GEOLOCATION-7654321"]
As shown in the example above, you can define the list values either line by line or as an array in YAML.
Note: When using a list parameter value in a JSON template, make sure to just reference the value without any extra brackets.
{
"emails": {{ .recipients }}
}
This differs from the sometimes used string list in v1, for which the template needed to include square brackets (for example, "emails": [ {{ .recipients }} ]
). When such lists are encountered when converting a v1 configuration, templates are automatically updated.
String escaping of config
In general, all YAML values are escaped before being added to a configuration uploaded to Dynatrace. This ensures that fully filled templates are valid JSON when uploading. Any newlines, special characters such as double quotes, and so on are escaped.
parameters:
name: "Dev"
example1: "This is \\n already escaped"
example2: "This will \n be escaped"
example3: This "will" be escaped too
text: |
This will also
be escaped
Overriding configuration per environment
There are many cases in which a configuration is similar but not the same between environments. Examples:
- An alert is sent to a different Slack channel for staging and production environments
- A service's configuration should be skipped because it's not yet released
To enable this, you can override values of configurations on an environment and environment-group level using the groupOverrides
and environmentOverrides
fields.
Both are generally defined in the same way, differing only in whether they're applied to a group or a single environment. You can define the group/environment name to target and any configuration properties to modify.
In the example below, a configuration will not be deployed (skipped) to the "production-environments" group and gets some special configuration applied for two environments:
configs:
- id: test-dashboard
type:
api: dashboard
config:
name: Test Dashboard
template: dashboard.json
parameters:
owner: Test User
content: "Some Text ..."
environmentOverrides:
- environment: dev-env-42
override:
name: Special Dev Dashboard
parameters:
content: "Some even better Text!"
- environment: staging-env-21
override:
name: Special Staging Dashboard
parameters:
content: "Some much better Text!"
groupOverrides:
- group: production-environments
override:
skip: true