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

SqlServerDsc: Try move ResourceBase into a seperate module so if can easily be reused by other modules #1790

Closed
johlju opened this issue Nov 5, 2022 · 2 comments · Fixed by #1826
Labels
enhancement The issue is an enhancement request.

Comments

@johlju johlju added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Nov 5, 2022
@johlju
Copy link
Member Author

johlju commented Dec 29, 2022

Some commands that should be public should be moved to DscResource.Common:

@johlju
Copy link
Member Author

johlju commented Dec 29, 2022

Verified on a lab server that there will be no confliict between modules using a module that contain ResourceBase.

Using the configuration:

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
        }
    }
}

It produced this output - not the Verbose statement is the important part, I removed verbose output that is not relevant.

We can see that

  • PSResourceRepository is using its own ResourceBase class; "USING RESOURCEBASE FROM COMPUTERMANAGEMENTDSC!"
  • SqlAudit is using its own ResourceBase class; "USING RESOUREBASE FROM SQLSERVERDSC!"
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows
/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer SQL01 with user sid S-1-5-21-1949799417-2769522740-2476083923-1107.
VERBOSE: [SQL01]: LCM:  [ Start  Set      ]
VERBOSE: [SQL01]: LCM:  [ Start  Resource ]  [[PSResourceRepository]Register PSGallery PSRepository]
VERBOSE: [SQL01]: LCM:  [ Start  Test     ]  [[PSResourceRepository]Register PSGallery PSRepository]
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] Determining the current state for resource 'PSResourceRepository' using the key property '{"Name":"PSGallery"}'. (RB0002)
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1'.
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1'.
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] USING RESOURCEBASE FROM COMPUTERMANAGEMENTDSC!
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] Getting the current state for resource 'PSResourceRepository' using the key property '{"Name":"PSGallery"}'. (RB0001)
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] Return the current state of the repository 'PSGallery'.
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] The repository 'PSGallery' was not found.
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] NOTMATCH: Value (type 'Ensure') for property 'Ensure' does not match. Current state is 'Absent' and desired state is 'Present'. (DRC0021)
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] NOTMATCH: Value (type 'Ensure') for property 'Ensure' does not match. Current state is 'Absent' and desired state is 'Present'. (DRC0021)
VERBOSE: [SQL01]:                            [[PSResourceRepository]Register PSGallery PSRepository] The current state is not the desired state. (RB0004)
VERBOSE: [SQL01]: LCM:  [ End    Test     ]  [[PSResourceRepository]Register PSGallery PSRepository]  in 20.7660 seconds.
VERBOSE: [SQL01]: LCM:  [ Start  Set      ]  [[PSResourceRepository]Register PSGallery PSRepository]
... 
VERBOSE: [SQL01]: LCM:  [ End    Set      ]  [[PSResourceRepository]Register PSGallery PSRepository]  in 74.9690 seconds.
VERBOSE: [SQL01]: LCM:  [ Start  Resource ]  [[SqlAudit]FileAudit_Server]
VERBOSE: [SQL01]: LCM:  [ Start  Test     ]  [[SqlAudit]FileAudit_Server]
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] Determining the current state for resource 'SqlAudit' using the key property '{"Name":"FileAudit","InstanceName":"SQL2022"}'. (RB0002)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] USING RESOUREBASE FROM SQLSERVERDSC!
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] Getting the current state for resource 'SqlAudit' using the key property '{"Name":"FileAudit","InstanceName":"SQL2022"}'. (RB0001)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] Evaluate the current audit 'FileAudit' on the instance 'SQL2022'. (SA0004)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] Importing PowerShell module 'SqlServer' with version '21.1.18256' from path 'C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18256\SqlServer.psm1'. (SQLCOMMON0025)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] Impersonate credential '[email protected]' with login type 'WindowsUser'. (SQLCOMMON0056)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] Connected to SQL instance 'localhost\SQL2022'. (SQLCOMMON0018)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] MATCH: Value (type 'Ensure') for property 'Ensure' does match. Current state is 'Absent' and desired state is 'Absent'. (DRC0020)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] MATCH: Value (type 'Ensure') for property 'Ensure' does match. Current state is 'Absent' and desired state is 'Absent'. (DRC0020)
VERBOSE: [SQL01]:                            [[SqlAudit]FileAudit_Server] The current state is the desired state. (RB0005)
VERBOSE: [SQL01]: LCM:  [ End    Test     ]  [[SqlAudit]FileAudit_Server]  in 11.4850 seconds.
VERBOSE: [SQL01]: LCM:  [ Skip   Set      ]  [[SqlAudit]FileAudit_Server]
VERBOSE: [SQL01]: LCM:  [ End    Resource ]  [[SqlAudit]FileAudit_Server]
VERBOSE: [SQL01]: LCM:  [ End    Set      ]

@johlju johlju added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Dec 29, 2022
johlju added a commit that referenced this issue Jan 3, 2023
- SqlServerDsc
  - Class-based resources now uses the parent class `ResourceBase` from the
    module _DscResource.Base_ (issue #1790).
  - Removed private function `Test-ResourceDscPropertyIsAssigned` and
    `Test-ResourceHasDscProperty`. Both are replaced by `Test-DscProperty`
    which is now part of the module _DscResource.Common_.
  - Removed private function `Get-DscProperty`. It is replaced by `Get-DscProperty`
    which is now part of the module _DscResource.Common_.
  - The class `ResourceBase` and `Reason` has been removed, they are now
    part of the module _DscResource.Base_.
  - The enum `Ensure` has been removed, is is now part of the module
    _DscResource.Base_.
  - The private functions that the class `ResourceBase` depended on has been
    moved to the module _DscResource.Base_.
    - `ConvertFrom-CompareResult`
    - `ConvertTo-Reason`
    - `Get-ClassName`
    - `Get-LocalizedDataRecursive`
@johlju johlju removed the in progress The issue is being actively worked on by someone. label Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant