Search code examples
azuredsc

Azure. How to deploy custom file referenced by DSC


I'm building an Azure RM Template that will install DSC on a target VM. DSC must use a .bacpac file. How can I upload that file to a target VM? How can I make it to be downloaded by target VM from GitHub and placed on a specific folder? The DSC configuration looks like this: https://github.com/PowerShell/xDatabase/blob/dev/Examples/Sample_xDatabase.ps1


Solution

  • Something like this:

    Import-DscResource -ModuleName PSDesiredStateConfiguration,xPSDesiredStateConfiguration,xDatabase
    
    Node $nodeName
    {
        LocalConfigurationManager
        {
            RebootNodeIfNeeded = $true
        }
    
        xRemoteFile BacPacPackage
        {  
            Uri             = "https://github.com/url_to_your_bacpac"
            DestinationPath = "c:\where_to_put_it"
            MatchSource     = $false
        } 
    
        xDatabase DeployBacPac
        {
            Ensure = "Present"
            SqlServer = $nodeName
            SqlServerVersion = $SqlServerVersion
            DatabaseName = $DatabaseName
            Credentials = $credential # credentials to access SQL
            BacPacPath = "c:\path_from_previous command"
            DependsOn = "[xRemoteFile]BacPacPackage"
        }
    }