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

SqlAudit: Using the property Reasons with type [Reason] fails if two modules have type [Reason] #1831

Closed
johlju opened this issue Jan 5, 2023 · 2 comments · Fixed by #1858
Labels
breaking change When used on an issue, the issue has been determined to be a breaking change. bug The issue is a bug. external The issue cannot be resolved within the DSC Resource Kit. good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub

Comments

@johlju
Copy link
Member

johlju commented Jan 5, 2023

Problem description

If two resources, each for an indvidual module, both have the property Reasons a configuration that uses those two resources fail to parse. This is because the code [DscProperty()] [Reasons[]] $Reasons fails to parse when it finds the same class name loaded in two modules.

@nyanhp found and reproduce this. @nyanhp created a repository that shows the issue with both class-based resources and MOF-based resources: https://github.com/nyanhp/DscRepro

Verbose logs

At line:11 char:5
+     Import-DscResource -ModuleName SqlServerDsc
+     ~~~~~~~~~~~~~~~~~~
Exception occurred when post-parsing dynamic keyword 'Import-DscResource' with details 'System.Management.Automation.PSInvalidOperationException: Resource name 'Reason' is already 
being used by another Resource or Configuration.

DSC configuration

# Both resources must have the read-only property `Reasons`.
Configuration Example
{
    param
    (
        [Parameter(Mandatory = $true)]
        [System.Management.Automation.PSCredential]
        $SqlAdministratorCredential
    )

    Import-DscResource -ModuleName ComputerManagementDsc
    Import-DscResource -ModuleName SqlServerDsc

    node localhost
    {
        PSResourceRepository 'Register PSGallery PSRepository'
        {
            Name    = 'PSGallery'
            Ensure  = 'Present'
            Default = $true
        }

        SqlAudit FileAudit_Server
        {
            Ensure       = 'Absent'
            ServerName   = 'localhost'
            InstanceName = 'SQL2022'
            Name         = 'FileAudit'
            Credential   = $SqlAdministratorCredential
        }
    }
}

Suggested solution

There is no fix for this as it is a external problem with PowerShell DSC. We must remove the property Reasons from the resource.

SQL Server edition and version

n/a

SQL Server PowerShell modules

n/a

Operating system

Windows Server

PowerShell version

WMF 5.x

SqlServerDsc version

v16.1.0-preview0009
@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. breaking change When used on an issue, the issue has been determined to be a breaking change. external The issue cannot be resolved within the DSC Resource Kit. good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub labels Jan 5, 2023
@johlju
Copy link
Member Author

johlju commented Jan 5, 2023

I labelled this a breaking change, but don't think we should bump major version for this change. It is more of a bug, and will only affect users that actually started using the property, and that will fail as soon as their configuration will use another resource from another module that also uses Reasons.

@johlju
Copy link
Member Author

johlju commented Jan 7, 2023

There should be no need to remove the property Reasons. See more information in issue dsccommunity/DscResource.Base#4.

@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change When used on an issue, the issue has been determined to be a breaking change. bug The issue is a bug. external The issue cannot be resolved within the DSC Resource Kit. good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant