Skip to content

Commit

Permalink
(CAT-1484) - Add ensurable property to resource
Browse files Browse the repository at this point in the history
This commit adds a ensurable property to each resource which does
not already have an ensure property defined. This has a couple of
beneifts:

1. Prevents issues as seen in CAT-1484, where puppet namevars and DSC
   keys differences arise. By default, puppet will ignore namevar
   changes if they are the only atrtibutes passed in a manifest. This is
   a design of puppet and makes sure as namevars should only identify a
   resource. DSC's key values behave differently to this.
2. Will now clearly show in docs that the resource CANNOT be ensured.

The property sets a default of 'false' and will only accept values of
'False' or 'false'. The value will not need to be specified in
manifests.
  • Loading branch information
jordanbreen28 committed Nov 7, 2023
1 parent 8c0e21e commit 35a8f69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Puppet.Dsc/internal/functions/Get-TypeContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ function Get-TypeContent {
} Else {
$FriendlyName = $Resource.FriendlyName
}
# We add an ensurable property to all DSC resources that don't have an ensure property
$ResourceIsEnsurable = ($Resource.ParameterInfo | Select-Object -ExpandProperty Name).Contains('ensure')
$NotEnsurable = [pscustomobject]@{
Name = 'ensurable'
DefaultValue = 'false'
Type = "Enum['False', 'false']"
Help = 'Default attribute added to all dsc types without an ensure property. This resource is not ensurable.'
mandatory_for_get = 'false'
mandatory_for_set = 'false'
is_parameter = 'false'
is_namevar = 'false'
mof_is_embedded = 'false'
mof_type = 'String'
}
# We only add the ensurable property if it's not already present
If (!$ResourceIsEnsurable) {
$Resource.ParameterInfo += $NotEnsurable
}
# It is not *currently* possible to reliably programmatically retrieve
# the description information for a DSC Resource via CIM instances or
# Get-DscResource or Get-Help.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ Function Get-TypeParameterContent {

ForEach ($Parameter in $ParameterInfo) {
if (![string]::IsNullOrEmpty($Parameter.name)) {
if ($Parameter.name -ne 'ensurable') {
$Parameter.name = "dsc_$($Parameter.name)"
}
New-Object -TypeName System.String @"
dsc_$($Parameter.name): {
$($Parameter.name): {
type: $(ConvertTo-PuppetRubyString -String ($Parameter.Type -split "`n" -join "`n ")),
$(
If ([string]::IsNullOrEmpty($Parameter.Help)) {
Expand Down

0 comments on commit 35a8f69

Please sign in to comment.