guitarrapc / GraniResource

PowerShell Desired State Configuration Resources for real production workload.
https://www.powershellgallery.com/packages/GraniResource
MIT License
43 stars 8 forks source link

cCredentialManager Resource should change Key from Target Property to Name property #65

Closed guitarrapc closed 7 years ago

guitarrapc commented 7 years ago

Description of Issue

CredentialManager supporting PsRunAsCredential to manage not only SYSTEM Account but others.

However if you wan to manage "same target with same credential" for multiple account is not supported.

Reproduce

With following configuration.

configuration Test
{
    Import-DscResource -Modulename GraniResource
    Node localhost
    {
        cCredentialManager System
        {
            Ensure = $Node.Ensure
            Target = $Node.Target
            Credential = $Node.Credential
        }

        cCredentialManager PsDscRunAsCredential
        {
            Ensure = $Node.Ensure
            Target = $Node.Target
            Credential = $Node.Credential
            PsDscRunAsCredential = $Node.PsDscRunAsCredential
        }
    }
}

$configurationData = @{
    AllNodes = @(
        @{
            NodeName = "localhost"
            PSDscAllowPlainTextPassword = $true
            PSDscAllowDomainUser = $true
            Ensure = "Present"
            Target = "PesterTest"
            Credential = New-Object PSCredential ("Hoge", ("fuga" | ConvertTo-SecureString -Force -AsPlainText))
            PsDscRunAsCredential = New-Object PSCredential ("YourUserName", ("YourAwesomePassword" | ConvertTo-SecureString -Force -AsPlainText))
        }
    )
}

Test -ConfigurationData $configurationData
Start-DscConfiguration -Verbose -Path .\Test -Wait -Force

You will see following errors.

Test-ConflictingResources : A conflict was detected between resources '[cCredentialManager]Present (::6::9::cCredentialManager)' and '[cCredentialManager]Present2 (::14::9::cCr
edentialManager)' in node 'localhost'. Resources have identical key properties but there are differences in the following non-key properties: 'PsDscRunAsCredential'. Values 'Sy
stem.Management.Automation.PSCredential' don't match values 'NULL'. Please update these property values so that they are identical in both cases.
At line:271 char:9
+         Test-ConflictingResources $keywordName $canonicalizedValue $k ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], InvalidOperationException
    + FullyQualifiedErrorId : ConflictingDuplicateResource,Test-ConflictingResources
Errors occurred while processing configuration 'Test'.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3705 char:5
+     throw $ErrorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Absent_System:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

Expectation

It's should support Same Target, Credential configuration for multiple PsDscRunAsCredential Accounts.

guitarrapc commented 7 years ago

Finish implementation and release ver.3.7.8.0 on PowerShell Galeery. https://www.powershellgallery.com/packages/GraniResource/3.7.7.0