Resource Block Precedence #
A given resource can be defined in multiple places. The resources will be merged together to create the final configuration for the resource.
Each of these files can define the same configuration. For example, to configure the txn
instance on node2
in this example, the following files would be used. Each lower file overrides the values in the higher file. The more specific file overrides the more general file.
defaults.hcl
nodes\node2.hcl
nodes\nodes2__txn.hcl
(note the double-underscore)
That means the LAST file processed overrides the previous files.
The full rules are
- Global Defaults:
defaults.hcl
- Per Computer Defaults (in order):
nodes\computer.hcl
nodes\computer__instance.hcl
(note the double underscores)
The PRO Edition adds Domains and Tags when determining precedence.
Merging Resource Blocks #
Each file processed overrides the attributes for the previous files. Consider the configurations for a database TXNDB on the SQL Server instance Node1\TXN
:
# nodes\node1.hcl
resource "database" "TXNDB" {
owner = "sa"
recovery_model = "simple"
ensure = "alter"
}
# nodes\node1__TXN.hcl
resource "database" "TXNDB" {
recovery_model = "full"
rcsi = true
ensure = "present"
}
The attributes from node1__txn.hcl
are merged into the attributes from node.hcl
to configure TXNDB. The resulting database would be ALTERed on the root instance of node1. On the TXN instance, the result would be this:
resource "database" "TXNDB" {
owner = "sa"
recovery_model = "full"
rcsi = true
ensure = "present"
}
This would create the database if it wasn’t present. The owner
attribute is carried from node1.hcl
while the recovery_model
is overridden by node1__txn.hcl
.