Part 4: Adding modules to your ARM templates

Sitecore 9 in Azure Paas for Dummies

Preface

In this fourth post of the Sitecore 9 in Azure Paas series we are going to add custom modules from the marketplace to our Azure PAAS solution and add them to our ARM templates so that they are automaticly deployed.

In this post, we will show you how to add the Sitecore Powershell Extentions to our solution. The same method can be applied on other modules like Data Exchange Framework or other modules you download from the marketplace.

Resources

You can download all resources related to this article here.

deployment-part4

Convert the module

The first step to obtain our goal is to download the original module and convert is into a Sitecore webdeploy package (scwdp).

The sitecore powershell extentions can be downloaded here.

For the conversion of the module, a task is available in the Azure toolkit.

You can run it like this:

$Origin = "c:\Downloads\Sitecore PowerShell Extensions-4.7.2 for Sitecore 8.zip"
$Destination = "c:\Projects\ols\Source\deployment\Packages\"
Import-Module "C:\Software\Azure Toolkit\Sitecore Azure Toolkit 2.0.0 rev.171010\tools\Sitecore.Cloud.Cmdlets.dll" -Verbose
$wdpPath = ConvertTo-SCModuleWebDeployPackage -Path $Origin -Destination $Destination -Force

This will create a .scwpd.zip file in the destination directory.

 

Create a version without database for redeploy

Next we need to create a version of this .scwpd.zip file this does not contain the database script so that we can use this in our redeploy scripts to stay compatible with blue/green deployment.

Details on how to create this -nodb.scwpd.zip file can be found in the second part of this blog: “Strip the database”.

 

Extend the ARM templates

There are 2 options here:

  1. Extend the existing nested/application.json template
  2. Create a new nested/application-powershellextentions.json template

For this tutorial, we are going to go with option 1 and extend the existing template. Once you have the hang of this, you should be able to figure out the second yourself, if desired.

Now, in the nested/application.json file, find the resource with the name

“name”: “[concat(variables(‘cmWebAppNameTidy’), ‘/’, ‘MSDeploy’)]”

In the addon section of this resource we need to add these lines:

{
	"packageUri": "[parameters('powerShellExtensionsMsDeployPackageUrl')]",
	"AppOffline": true,
	"setParameters": {
	  "Application Path": "[variables('cmWebAppNameTidy')]",
	  "Core Admin Connection String": "[concat('Encrypt=True;TrustServerCertificate=False;Data Source=', variables('sqlServerFqdnTidy'), ',1433;Initial Catalog=',variables('coreSqlDatabaseNameTidy'),';User Id=', parameters('sqlServerLogin'), ';Password=', parameters('sqlServerPassword'), ';')]",          
	  "Master Admin Connection String": "[concat('Encrypt=True;TrustServerCertificate=False;Data Source=', variables('sqlServerFqdnTidy'), ',1433;Initial Catalog=',variables('masterSqlDatabaseNameTidy'),';User Id=', parameters('sqlServerLogin'), ';Password=', parameters('sqlServerPassword'), ';')]"
	 }
}
 In this particular case there are 3 setParameters to pass along.
To know which parameters you should add, open the .scwpd.zip files and look for the parameters.xml file. This contains the parameters you should pass along.
In the piece of template we just added, there is one new parameter from the file “powerShellExtensionsMsDeployPackageUrl”. We will pass this parameter to the script from our azuredeploy.parameters.json file. It should contain the location of our .scwpd.zip file (or the nodb variant in case of a redeploy).
In order to make this parameter available, we should extend the /nested/application.json file with this snippit in the parameters section.
    "powerShellExtensionsMsDeployPackageUrl": {
      "type": "securestring",
      "minLength": 1
    }

Master ARM template

Next, we need to configure the master arm template azuredeploy.json to take in this new parameter and pass it to the nested/application.json template.

First add this snippet into the main parameters section

    "powerShellExtensionsMsDeployPackageUrl": {
      "type": "securestring",
      "minLength": 1
    }

Second add this snippet into the resource with the name “name”: “[concat(deployment().name, ‘-application’)]”,

"powerShellExtensionsMsDeployPackageUrl": {
   "value": "[parameters('powerShellExtensionsMsDeployPackageUrl')]"
}

Azuredeploy.parameters.json

Finally, we should add the location of the powershell extensions scwpd module into our azuredeploy.parameters.json files. "powerShellExtensionsMsDeployPackageUrl": { "value": "https://mystorage.blob.core.windows.net/sitecore/Packages/Modules/Sitecore%20PowerShell%20Extensions-4.7%20for%20Sitecore%208.scwdp.zip" }

Next Steps

Et voila! You have now updated your scripts to install the powershell extentions into your sitecore PAAS solution.

Note that we just added it to the CM environment in this particular case, as this is the only environment where we want the module to be installed. The procedure to add it to CD, PROC or REP is just the same as for the CM.

This series of Sitecore 9 in Azure Paas for Dummies is nearly completed.

The final blogpost in this series will discuss this subject:

 

Leave a Reply