Desired State Variables Resolution

Hi There,

I’m working on a DSC definition for an IIS setup where I have a PSD1 file with the variables and another file with the DesiredState Configuration, as shown below:

psd1 file
@{
    AllNodes = @(
         @{
              NodeName = 'localhost'
  ...
              Folders = @(
                    @{
                        id          = 'SiteAFolder'
                        state       = 'present'
                        phy_path    = 'c:\wwwroot\SiteAFolder'
                    }
                    @{
                        id          = 'SiteBFolder'
                        state       = 'present'
                        phy_path    = 'c:\wwwroot\SiteBFolder'
                    }
              )
              WebAppPools = @(
                    @{
                        id          = 'SiteAPool'
                        ensure      = 'present'
                        state       = 'started'
                        name        = 'SiteAPool'
                        DependsOn   = 'SiteAFolder' 
                     }
                    @{
                        id          = 'SiteBPool'
                        ensure      = 'present'
                        state       = 'started'
                        name        = 'SiteBPool'
                        DependsOn   = 'SiteBFolder' 
                     }
              )
              WebSites = @(
                    @{
                        id          = 'SiteA'
                        ensure      = 'present'
                        state       = 'started'
                        name        = 'www.siteA.com'
                        WebAppPool  = 'SiteAPool'
                        Folder      = 'SiteAFolder'' 
                        HTTP_Port   = '80'
                        HTTPS_Port  = '443'
                        SSL_Thumb   = '...'
                        SSL_Store   = 'WebHosting'
                     }
                    @{
                        id          = 'SiteB'
                        ensure      = 'present'
                        state       = 'started'
                        name        = 'www.siteB.com'
                        WebAppPool  = 'SiteBPool'
                        Folder      = 'SiteBFolder'' 
                        HTTP_Port   = '80'
                        HTTPS_Port  = '443'
                        SSL_Thumb   = '...'
                        SSL_Store   = 'WebHosting'
                     }
              )
DSC file
 # Configure Sites
   Configuration SiteConfiguration {
 
    Import-DscResource –ModuleName 'PSDesiredStateConfiguration', 'xWebAdministration'
  
    node $AllNodes.NodeName {
...
     $Node.Folders.ForEach({
       File $_.id {
         Ensure = "Present"
         Type = 'Directory'
         DestinationPath = $_.phy_path
       }
    })
    $Node.WebAppPools.ForEach({
       xWebAppPool $_.id {
         Ensure          = $_.ensure
         State           = $_.state
         Name            = $_.name
         DependsOn       = '[File]' + $_.DependsOn
     }
  })
  $Node.WebSites.ForEach({
     xWebsite $_.id {
       Ensure          = $_.ensure
       State           = $_.state
       Name            = $_.name
       ApplicationPool = '[xWebAppPool]' + $_.WebAppPool
       PhysicalPath    = '[Folder]' + $_.folder
 
...

The point is… everything seems to work fine, however after the definitions are applied I noticed that the ApplicationPool and PhysicalPath variables for xWebsite aren’t being resolved to the respective expected configs. On IIS configuration, the former is set to '[xWebAppPool]'SiteAPool and '[Folder]'SiteAFolder, rather than SiteAPool and c:\wwwroot\SiteAFolder, respectively.

It seems that DSC is not capable to resolve the variables based on IDs. When I set the names directly, instead of variables, it works as expected.

Does anyone has seen this before and can give a clue how to make this work using variables?

Thanks in advance,

Why did you prefix them with the resource names ?
try

ApplicationPool = $_.WebAppPool
PhysicalPath    = $_.folder

Hi @kvprasoon , thanks for your response. I’ve tried this also but I’ve got the error below.

 PowerShell DSC resource MSFT_xWebSite  failed to execute Set-TargetResource functionality with error message: Failure to successfully create the website 
"www.siteA.com". Error: "Parameter 'PhysicalPath' should point to existing path.". 

Actually, I was expecting this error since the issue is exactly about DSC not being able to cross-reference previously created resource by their names. Funny enough is that for DependsOn, the cross-reference seems to work.

I was expecting that setting e.g PhysicalPath as [xWebAppPool] SiteAFolder, DSC would be able to resolve this to c:\wwwroot\SiteAFolder. This is not happening though.

You have to put DependsOn with Folder resource. In your case the name will be dynamic as its inside a foreach,

Hi @kvprasoon , actually the code snippet didn’t show, but DependsOn is there for xWebsite already.

    $Node.WebSites.ForEach({
       xWebsite $_.id {
         Ensure          = $_.ensure
         State           = $_.state
         Name            = $_.name
         ApplicationPool = '[xWebAppPool]' + $_.WebAppPool
         PhysicalPath    = '[Folder]' + $_.folder
 
         BindingInfo     = @( MSFT_xWebBindingInformation
                             {
                 )
 ...        
         DependsOn       = '[File]' + $_.Folder
       }
    }) 

is this a typo ? Folder = 'SiteAFolder'' there are two closing single quotes in the configuraition you have shared initially !

Hi @kvprasoon , it was a typo while I was editing to paste here (I didn’t some renaming) .

can you share the contents of the MoF file.