diff --git a/docs/architecture/decisions/0001-force-ensurable.md b/docs/architecture/decisions/0001-force-ensurable.md deleted file mode 100644 index a52dd2e8..00000000 --- a/docs/architecture/decisions/0001-force-ensurable.md +++ /dev/null @@ -1,50 +0,0 @@ -# 1. Force Ensurable = false on Non-ensurable resources - -Date: 2023-11-07 - -## Status - -Accepted - -## Context - -In CAT-1484, it was found that there was a mismatch in behaviour between dsc resource keys and puppet namevars. It was widely assumed that these two attribute types eseentially behaved the same, which was found not to be the case with the dsc_virtualmemory resource (and others) in the ComputerManagementDsc module. -Puppet uses namevars as identifiers, so when a manifest is passed containing only namevar attributes, puppet will ignore the updating values in a manifest and not attempt to update the resource, For example, the Puppet File resource has a single namevar equal to the path of the resource, say "/tmp/foo1.txt". If this namevar is changed to something like "/tmp/foo2.txt", then the original resource identified by the namevar will not be updated or changed; a new File resource will instead be created. In similar fashion, DSC uniquely identifies its resources with namevars and will update the dsc resource only when key attributes are passed. - -So although they appear the same on the surface, it was found that the below manifest and .mof file **would not** produce the same outcome on the target machine. - -```puppet -dsc_virtualmemory { 'CDrive': - dsc_drive => 'C', # namevar - dsc_type => 'AutoManagePagingFile', #namevar -} -``` - -```powershell -Configuration VirtualMemory_SetVirtualMemory_Config -{ - Import-DSCResource -ModuleName ComputerManagementDsc - - Node localhost - { - VirtualMemory PagingSettings - { - Type = 'AutoManagePagingFile' #Key - Drive = 'C' #Key - } - } -} -``` - -Although the content of both files are essentially equal, the DSC resource will apply the specified changes, puppet will not. - -## Decision - -We have decided to force an ensurable property on every DSC resource type that has no ensure parameter already present. This has a couple of benefits: - -1. Now documentation will clearly show that ensurable can only be set to false on certain types i.e. that they are not ensurabled by puppet. -2. The default value of false ensures that this is always passed along side namevar only manifests, preventing puppet from DSC key attribute updates like above. - -## Consequences - -Each initial puppet run after this change is applied will show as creating/updating of a resource. This will only occur on the first run and not any subsequent, true to the nature of Puppet. diff --git a/src/Puppet.Dsc/internal/functions/Get-TypeContent.ps1 b/src/Puppet.Dsc/internal/functions/Get-TypeContent.ps1 index 93643039..bc4eb9e5 100644 --- a/src/Puppet.Dsc/internal/functions/Get-TypeContent.ps1 +++ b/src/Puppet.Dsc/internal/functions/Get-TypeContent.ps1 @@ -36,24 +36,6 @@ 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 = 'Boolean[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. diff --git a/src/Puppet.Dsc/internal/functions/Get-TypeParameterContent.ps1 b/src/Puppet.Dsc/internal/functions/Get-TypeParameterContent.ps1 index 56b1a8b1..9e814b1b 100644 --- a/src/Puppet.Dsc/internal/functions/Get-TypeParameterContent.ps1 +++ b/src/Puppet.Dsc/internal/functions/Get-TypeParameterContent.ps1 @@ -24,11 +24,8 @@ 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 @" - $($Parameter.name): { + dsc_$($Parameter.name): { type: $(ConvertTo-PuppetRubyString -String ($Parameter.Type -split "`n" -join "`n ")), $( If ([string]::IsNullOrEmpty($Parameter.Help)) {