PRO: Roles #
All features described on this page are part of the Professional Edition.
While in beta, you can enable the Professional Edition by creating an empty
key.xtfile next to thesqldsc.exefile.The PRO edition will become a paid version. Until then, PRO features expire 90 days after the build date. Please see https://www.scalesql.com for updated builds or run
sqldsc update.
Roles #
Roles changed in 1.39. Please see the Breaking Changes section if you are upgrading.
Each target can be assigned multiple roles. Instances in roles can be given identical configuration. Good uses of roles include:
- Identical configuration of an AG
- Separate DEV from PROD
- Group servers together for processing
- Group servers in different data centers together
Targets #
A targets.hcl file looks something like this
target_defaults {
roles = ["baseline"]
}
target "D40" {}
target "node1.domain1.com" {
roles = ["prod", "data-center-2", "ag-one"]
force_roles = true
}
target "server04" {
roles = ["local-backups"]
}
- The
target_defaultssection can define a base set of roles for every target. - D40 only has the
baselineroles. - node1 has three roles and doesn’t have the
baselinerole. Therolesfield withforce_roles=truefor a target overrides therolesfield in thetarget_defaults. - server04 ends up with two roles:
baselineandlocal-backups. Therolesfield (withoutforce_roles) adds the roles to the default roles. - Because the
target_defaultsblock is per file (i.e. per domain), each domain can get a different set of default roles.
Nested Roles #
A role can define child roles using the optional roles attribute. The baseline.hcl from the example above might look like this:
roles = ["logging", "monitor-login"]
// more configuration settings...
This changes the example above in the following way:
- D40 now has three roles. It has
baselineas well asloggingandmonitor-login. - node1 still only has three roles.
force_rolesprevents the expanding of nested nodes as well as inherting the default nodes. - server04 now has four roles instead of two. It adds
loggingandmonitor-loginthat are in thebaseline.hclfile.
The main use case for this is Availability Groups. Typically one role is created for an AG.
That role can then specify the needed roles inside it. That simplifies the nodes in the target files and allow more granular roles.
Role Order Matters #
- The Resources from the roles are processed in order the roles are specified
- List more general roles followed by more specific
- Remember that Resource in later roles can override resources in earlier roles
Configuration #
The name of a role must match a file name in the roles directory. The init command doesn’t create the roles folder.
config\
nodes\
DOMAIN1\
node1.hcl
server1.hcl
roles\
ag-one.hcl
baseline.hcl
data-center-1.hcl
data-center-2.hcl
prod.hcl
defaults.hcl
targets.hcl
DOMAIN1.targets.hcl
Breaking change in 1.39 #
The attribute names that Targets use to add to and override the default roles have changed (again) to make them simpler and more explicit. See below to update your repository. The target_defaults block in a Targets file can define an array of roles using the roles attribute. Targets can override these or add more roles. This is unchanged.
- Prior to version 1.36, a Target could have one of the following two attributes
added_roles– roles that are added to any default rolesroles– set the list of roles for this target
- Starting in version 1.36, a Target can have one of the two following attributes
add_roles– roles that are added to any default rolesonly_roles– set the list of roles for this target
- Starting in version 1.39, a Target can have the two following attributs
roles– roles that are added to the default rolesforce_roles– changesrolesso that only those roles are used. There is no inheritance.
Updating your repository from 1.36 #
- For targets, rename
add_roles=[...]toroles=[...] - For targets, rename
only_roles=[...]toroles=[...]and addforce_roles=true - In
/config/state/repository.toml, update the version to 3 (version=3). This file is created starting in 1.36 and will need to checked into your repository.
The documentation for the earlier behavior is further down the page.
Roles (prior to 1.39) #
Each target can be assigned multiple roles. Instances in roles can be given identical configuration. Good uses of roles include:
- Identical configuration of an AG
- Separate DEV from PROD
- Group servers together for processing
- Group servers in different data centers together
Targets #
A targets.hcl file looks something like this
target_defaults {
roles = ["baseline"]
}
target "D40\SQL2016" {}
target "server1.domain1.com" {
only_roles = ["baseline", "data-center-1"]
}
target "node1.domain1.com" {
only_roles = ["prod", "data-center-2", "ag-one"]
}
target "server04" {
add_roles = ["local-backups"]
}
- The
target_defaultssection can define a base set of roles for every target. - The
only_rolesfield for a target overrides therolesfield in thetarget_defaults. In the example,node1has three roles and doesn’t have thebaselinerole. - The
add_rolesfield adds the roles to the default roles. In the example,server04ends up with two roles:baselineandlocal-backups. - Because the
target_defaultsblock is per file (i.e. per domain), each domain can get a different set of default roles.
Role Order Matters #
- The Resources from the roles are processed in order the roles are specified
- List more general roles followed by more specific
- Remember that Resource in later roles can override resources in earlier roles
Configuration #
The name of a role must match a file name in the roles directory. The init command doesn’t create the roles folder.
config\
nodes\
DOMAIN1\
node1.hcl
server1.hcl
roles\
ag-one.hcl
baseline.hcl
data-center-1.hcl
data-center-2.hcl
prod.hcl
defaults.hcl
targets.hcl
DOMAIN1.targets.hcl
Roles (prior to 1.36) #
Each target can be assigned multiple roles. Instances in roles can be given identical configuration. Good uses of roles include:
- Identical configuration of an AG
- Separate DEV from PROD
- Group servers together for processing
- Group servers in different data centers together
Targets #
A targets.hcl file looks something like this
target_defaults {
roles = ["baseline"]
}
target "D40\SQL2016" {}
target "server1.domain1.com" {
roles = ["baseline", "data-center-1"]
}
target "node1.domain1.com" {
roles = ["prod", "data-center-2", "ag-one"]
}
target "server04" {
added_roles = ["local-backups"]
}
- The
target_defaultssection can define a base set of roles for every target. - The
rolesfield for a target overrides therolesfield in thetarget_defaults. In the example,node1has three roles and doesn’t have thebaselinerole. - The
added_rolesfield adds the roles to the default roles. In the example,server04ends up with two roles:baselineandlocal-backups. - Because the
target_defaultsblock is per file (i.e. per domain), each domain can get a different set of default roles.
Role Order Matters #
- The Resources from the roles are processed in order the roles are specified
- List more general roles followed by more specific
- Remember that Resource in later roles can override resources in earlier roles
Configuration #
The name of a role must match a file name in the roles directory. The init command doesn’t create the roles folder.
config\
nodes\
DOMAIN1\
node1.hcl
server1.hcl
roles\
ag-one.hcl
baseline.hcl
data-center-1.hcl
data-center-2.hcl
prod.hcl
defaults.hcl
targets.hcl
DOMAIN1.targets.hcl