Variables in the DSC resource?

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Глеб Боушев Глеб Боушев 1 month, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #51689

    Hello, I've been banging my head on this stuff for a while, so lets imagine I have a resource:

    Configuration WebProxy
    {     
    Param (
        [Parameter(Mandatory=$true)][string] $url
        )
    Import-DscResource -Module nx
    Node webproxy {  
            nxFile ProxyConf 
            {
                SourcePath = "$url_variable_goes_here"
                DestinationPath = '/etc/nginx/sites-available/proxy'
            }  
        }
    }

    So, I figured I could use configdata, but that's not convinient, I'd like to be able to pass value from pipeline at mof compile time, is that possible?

    #51716
    Profile photo of Luke Griffith
    Luke Griffith
    Participant

    Hi there,

    Should be more than possible, inside the configuration block its just standard powershell, of course the data you pass in will need to be a property on the DSC resource, but inside the config block you can run any standard powershell code, and this will be executed at compile time when you generate the mof.

    Say in theory, you created a function that would obtain the source path URL variable, you could execute the function inside the configuration block, store that in a variable and pass it in. All this logic would be executed at the MOF compile time and be deserialized into the MOF format.

    
    Configuration WebProxy
    {     
    Param (
        [Parameter(Mandatory=$true)][string] $url
        )
    Import-DscResource -Module nx
    
    $url = Get-SourcePathUrl
    
    Node webproxy {  
            nxFile ProxyConf 
            {
                SourcePath =  $url
                DestinationPath = '/etc/nginx/sites-available/proxy'
            }  
        }
    }
    
    
    #51769

    Well, turns out you can just use "text" + $var + "text", who knew. Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.