No, not directly in the way you've written it, because Puppet's resource { default: ... } block applies defaults before individual resource declarations are processed, and there's no built-in mechanism to reference the "default" value of a parameter from within a specific resource's declaration to then concatenate or modify it.
When you write:
'actual_resource':
par1 => default + [val2],
default here isn't a keyword that references the value of par1 from the default block. It would be interpreted as a literal string or an undefined variable, leading to a compilation error.
The Puppet Way to Achieve This: Use a Variable for the Base Array
The most common and idiomatic Puppet way to achieve what you want is to define the base array in a variable and then use that variable in both your default block and your specific resource declarations, concatenating as needed.
Example:
# Define your base array of values
$common_par1_values = ['val1']
# Apply these values as a default
resource {
default:
par1 => $common_par1_values,
# ... other defaults ...
;
# Your specific resource declaration
'actual_resource':
# Now you can concatenate!
par1 => $common_par1_values + ['val2'], # Result for 'actual_resource': ['val1', 'val2']
;
# Another resource that just uses the default
'another_resource':
# Result for 'another_resource': ['val1']
;
# A third resource that completely overrides the default
'override_resource':
par1 => ['val3', 'val4'], # Result for 'override_resource': ['val3', 'val4']
;
}
# --- For demonstration, let's assume 'my_resource' is a valid resource type ---
# You'd typically use a define or a native resource type like 'file', 'exec', etc.
# For this example, let's pretend 'my_resource' exists and has a 'par1' attribute
define my_resource($par1) {
notify { "Resource ${name} par1: ${par1}": }
}
# When you compile this, you'd see:
# Notify[Resource actual_resource par1: ["val1", "val2"]]
# Notify[Resource another_resource par1: ["val1"]]
# Notify[Resource override_resource par1: ["val3", "val4"]]
Explanation:
$common_par1_values = ['val1']: You define a standard Puppet variable that holds the initial array.
default: par1 => $common_par1_values,: You use this variable to set the default value for par1 for all resources declared within this resource { ... } block.
'actual_resource': par1 => $common_par1_values + ['val2'],: For actual_resource, you reference the same base variable and then use Puppet's array concatenation operator (+) to add val2 to it. This creates a new array ['val1', 'val2'] specifically for actual_resource.
This approach keeps your common defaults in one place (the variable) and allows specific resources to extend or override them as needed.