Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Puppet type conversions to expected Powershell types #216

Closed
nickgw opened this issue Apr 27, 2022 · 2 comments
Closed

Support Puppet type conversions to expected Powershell types #216

nickgw opened this issue Apr 27, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@nickgw
Copy link

nickgw commented Apr 27, 2022

Use Case

Trying to migrate from puppetlabs/dsc to puppet.dsc generated modules is a chore because puppetlabs/dsc handles puppet types being passed to Powershell correctly. IE: dsc_ensure => present, is valid, but in puppet.dsc, dsc_ensure must be one of "Present" or "Absent". Similarly, passing puppet bool to dsc resources works correctly in puppetlabs/dsc but must be "True" or "False" in puppet.dsc

Describe the Solution You Would Like

I'd appreciate the same functionality as in puppetlabs/dsc. I could see a solution being if a param is an enum downcase them before comparing and handling translating booleans so they dont need to be capitalized strings.

Describe Alternatives You've Considered

A clear and concise description of any alternative solutions or features you've considered.

Additional Context

Add any other context or screenshots about the feature request here.

@nickgw nickgw added the enhancement New feature or request label Apr 27, 2022
@nickgw
Copy link
Author

nickgw commented Nov 2, 2022

Circling back on this, changing this block:

  If (![String]::IsNullOrEmpty($DscResourceProperty.Values)) {
    # Enums are handles specially
    $InnerText = $DscResourceProperty.Values | ForEach-Object -Process { "'$_'" }
    $PuppetDataTypeText = "Enum[$($InnerText -join ', ')]"
  } 

in https://github.com/puppetlabs/Puppet.Dsc/blob/main/src/internal/functions/Get-PuppetDataType.ps1#L45
to:

  If (![String]::IsNullOrEmpty($DscResourceProperty.Values)) {
    # Enums are handles specially
    $InnerText = $DscResourceProperty.Values | ForEach-Object -Process { "'$_'" }
    $InnerText += $InnerText | ForEach-Object -Process {"$($_.toLower())" }
    $InnerText = $InnerText | Select-Object -Unique
    $PuppetDataTypeText = "Enum[$($InnerText -join ', ')]"
  } 

Would resolve a majority of the headaches. For a property values of:
$DscResourceProperty = @{Values = @('Install', 'Upgrade', 'InstallFailoverCluster', 'AddNode', 'PrepareFailoverCluster', 'CompleteFailoverCluster')}
The current result of that block is :
Enum['Install', 'Upgrade', 'InstallFailoverCluster', 'AddNode', 'PrepareFailoverCluster', 'CompleteFailoverCluster']

with the suggested change it is:
Enum['Install', 'Upgrade', 'InstallFailoverCluster', 'AddNode', 'PrepareFailoverCluster', 'CompleteFailoverCluster', 'install', 'upgrade', 'installfailovercluster', 'addnode', 'preparefailovercluster', 'completefailovercluster']

@nickgw
Copy link
Author

nickgw commented Nov 12, 2022

1.0.4 includes code to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant