Deploy a Cloud Service (extended support) using ARM templates
This tutorial explains how to create a Cloud Service (extended support) deployment using ARM templates.
Before you begin
Review the deployment prerequisites for Cloud Services (extended support) and create the associated resources.
Create a new resource group using the Azure portal or PowerShell. This step is optional if you are using an existing resource group.
Create a new storage account using the Azure portal or PowerShell. This step is optional if you are using an existing storage account.
Upload your Package (.cspkg) and Service Configuration (.cscfg) files to the storage account using the Azure portal, or PowerShell. Obtain the SAS URIs of both files to be added to the ARM template later in this tutorial.
(Optional) Create a key vault and upload the certificates.
- Certificates can be attached to cloud services to enable secure communication to and from the service. In order to use certificates, their thumbprints must be specified in your Service Configuration (.cscfg) file and uploaded to a key vault. A key vault can be created through the Azure portal or PowerShell.
- The associated key vault must be located in the same region and subscription as cloud service.
- The associated key vault for must be enabled appropriate permissions so that Cloud Services (extended support) resource can retrieve certificates from Key Vault. For more information, see Certificates and Key Vault
- The key vault needs to be referenced in the OsProfile section of the ARM template shown in the below steps.
Deploy a Cloud Service (extended support)
Note
An easier and faster way of generating your ARM template and parameter file is via the Azure portal. You can download the generated ARM template via the portal to create your Cloud Service via PowerShell
Create virtual network. The name of the virtual network must match the references in the Service Configuration (.cscfg) file. If using an existing virtual network, omit this section from the ARM template.
"resources": [ { "apiVersion": "2019-08-01", "type": "Microsoft.Network/virtualNetworks", "name": "[parameters('vnetName')]", "location": "[parameters('location')]", "properties": { "addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] }, "subnets": [ { "name": "WebTier", "properties": { "addressPrefix": "10.0.0.0/24" } } ] } } ]
If creating a new virtual network, add the following to the
dependsOn
section to ensure the platform creates the virtual network prior to creating the cloud service."dependsOn": [ "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]" ]
Create a public IP address and (optionally) set the DNS label property of the public IP address. If you are using a Static IP you need to reference it as a Reserved IP in Service Configuration (.cscfg) file. If using an existing IP address, skip this step and add the IP address information directly into the load balancer configuration settings of your ARM template.
"resources": [ { "apiVersion": "2019-08-01", "type": "Microsoft.Network/publicIPAddresses", "name": "[parameters('publicIPName')]", "location": "[parameters('location')]", "properties": { "publicIPAllocationMethod": "Dynamic", "idleTimeoutInMinutes": 10, "publicIPAddressVersion": "IPv4", "dnsSettings": { "domainNameLabel": "[variables('dnsName')]" } }, "sku": { "name": "Basic" } } ]
If creating a new IP address, add the following to the
dependsOn
section to ensure the platform creates the IP address prior to creating the cloud service."dependsOn": [ "[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPName'))]" ]
Create a Cloud Service (Extended Support) object, adding appropriate
dependsOn
references if you are deploying Virtual Networks or Public IP within your template.{ "apiVersion": "2021-03-01", "type": "Microsoft.Compute/cloudServices", "name": "[variables('cloudServiceName')]", "location": "[parameters('location')]", "tags": { "DeploymentLabel": "[parameters('deploymentLabel')]", "DeployFromVisualStudio": "true" }, "dependsOn": [ "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]", "[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPName'))]" ], "properties": { "packageUrl": "[parameters('packageSasUri')]", "configurationUrl": "[parameters('configurationSasUri')]", "upgradeMode": "[parameters('upgradeMode')]" } }
Create a Network Profile Object for your Cloud Service and associate the public IP address to the frontend of the load balancer. A Load balancer is automatically created by the platform.
"networkProfile": { "loadBalancerConfigurations": [ { "id": "[concat(variables('resourcePrefix'), 'Microsoft.Network/loadBalancers/', variables('lbName'))]", "name": "[variables('lbName')]", "properties": { "frontendIPConfigurations": [ { "name": "[variables('lbFEName')]", "properties": { "publicIPAddress": { "id": "[concat(variables('resourcePrefix'), 'Microsoft.Network/publicIPAddresses/', parameters('publicIPName'))]" } } } ] } } ] }
Add your key vault reference in the
OsProfile
section of the ARM template. Key Vault is used to store certificates that are associated to Cloud Services (extended support). Add the certificates to Key Vault, then reference the certificate thumbprints in Service Configuration (.cscfg) file. You also need to enable Key Vault 'Access policies' for 'Azure Virtual Machines for deployment'(on portal) so that Cloud Services (extended support) resource can retrieve certificate stored as secrets from Key Vault. The key vault must be located in the same region and subscription as cloud service and have a unique name. For more information, see using certificates with Cloud Services (extended support)."osProfile": { "secrets": [ { "sourceVault": { "id": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.KeyVault/vaults/{keyvault-name}" }, "vaultCertificates": [ { "certificateUrl": "https://{keyvault-name}.vault.azure.net:443/secrets/ContosoCertificate/{secret-id}" } ] } ] }
Note
SourceVault is the ARM Resource ID to your key vault. You can find this information by locating the Resource ID in the properties section of your key vault.
- certificateUrl can be found by navigating to the certificate in the key vault labeled as Secret Identifier.
- certificateUrl should be of the form https://{keyvault-endpoin}/secrets/{secretname}/{secret-id}
Create a Role Profile. Ensure that the number of roles, role names, number of instances in each role and sizes are the same across the Service Configuration (.cscfg), Service Definition (.csdef) and role profile section in ARM template.
"roleProfile": { "roles": { "value": [ { "name": "WebRole1", "sku": { "name": "Standard_D1_v2", "capacity": "1" } }, { "name": "WorkerRole1", "sku": { "name": "Standard_D1_v2", "capacity": "1" } } ] } }
(Optional) Create an extension profile to add extensions to your cloud service. For this example, we are adding the remote desktop and Windows Azure diagnostics extension.
Note
The password for remote desktop must be between 8-123 characters long and must satisfy at least 3 of password complexity requirements from the following: 1) Contains an uppercase character 2) Contains a lowercase character 3) Contains a numeric digit 4) Contains a special character 5) Control characters are not allowed
"extensionProfile": { "extensions": [ { "name": "RDPExtension", "properties": { "autoUpgradeMinorVersion": true, "publisher": "Microsoft.Windows.Azure.Extensions", "type": "RDP", "typeHandlerVersion": "1.2.1", "settings": "<PublicConfig>\r\n <UserName>[Insert Username]</UserName>\r\n <Expiration>1/21/2022 12:00:00 AM</Expiration>\r\n</PublicConfig>", "protectedSettings": "<PrivateConfig>\r\n <Password>[Insert Password]</Password>\r\n</PrivateConfig>" } }, { "name": "Microsoft.Insights.VMDiagnosticsSettings_WebRole1", "properties": { "autoUpgradeMinorVersion": true, "publisher": "Microsoft.Azure.Diagnostics", "type": "PaaSDiagnostics", "typeHandlerVersion": "1.5", "settings": "[parameters('wadPublicConfig_WebRole1')]", "protectedSettings": "[parameters('wadPrivateConfig_WebRole1')]", "rolesAppliedTo": [ "WebRole1" ] } } ] }
Review the full template.
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "cloudServiceName": { "type": "string", "metadata": { "description": "Name of the cloud service" } }, "location": { "type": "string", "metadata": { "description": "Location of the cloud service" } }, "deploymentLabel": { "type": "string", "metadata": { "description": "Label of the deployment" } }, "packageSasUri": { "type": "securestring", "metadata": { "description": "SAS Uri of the CSPKG file to deploy" } }, "configurationSasUri": { "type": "securestring", "metadata": { "description": "SAS Uri of the service configuration (.cscfg)" } }, "roles": { "type": "array", "metadata": { "description": "Roles created in the cloud service application" } }, "wadPublicConfig_WebRole1": { "type": "string", "metadata": { "description": "Public configuration of Windows Azure Diagnostics extension" } }, "wadPrivateConfig_WebRole1": { "type": "securestring", "metadata": { "description": "Private configuration of Windows Azure Diagnostics extension" } }, "vnetName": { "type": "string", "defaultValue": "[concat(parameters('cloudServiceName'), 'VNet')]", "metadata": { "description": "Name of vitual network" } }, "publicIPName": { "type": "string", "defaultValue": "contosocsIP", "metadata": { "description": "Name of public IP address" } }, "upgradeMode": { "type": "string", "defaultValue": "Auto", "metadata": { "UpgradeMode": "UpgradeMode of the CloudService" } } }, "variables": { "cloudServiceName": "[parameters('cloudServiceName')]", "subscriptionID": "[subscription().subscriptionId]", "dnsName": "[variables('cloudServiceName')]", "lbName": "[concat(variables('cloudServiceName'), 'LB')]", "lbFEName": "[concat(variables('cloudServiceName'), 'LBFE')]", "resourcePrefix": "[concat('/subscriptions/', variables('subscriptionID'), '/resourceGroups/', resourceGroup().name, '/providers/')]" }, "resources": [ { "apiVersion": "2019-08-01", "type": "Microsoft.Network/virtualNetworks", "name": "[parameters('vnetName')]", "location": "[parameters('location')]", "properties": { "addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] }, "subnets": [ { "name": "WebTier", "properties": { "addressPrefix": "10.0.0.0/24" } } ] } }, { "apiVersion": "2019-08-01", "type": "Microsoft.Network/publicIPAddresses", "name": "[parameters('publicIPName')]", "location": "[parameters('location')]", "properties": { "publicIPAllocationMethod": "Dynamic", "idleTimeoutInMinutes": 10, "publicIPAddressVersion": "IPv4", "dnsSettings": { "domainNameLabel": "[variables('dnsName')]" } }, "sku": { "name": "Basic" } }, { "apiVersion": "2021-03-01", "type": "Microsoft.Compute/cloudServices", "name": "[variables('cloudServiceName')]", "location": "[parameters('location')]", "tags": { "DeploymentLabel": "[parameters('deploymentLabel')]", "DeployFromVisualStudio": "true" }, "dependsOn": [ "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]", "[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPName'))]" ], "properties": { "packageUrl": "[parameters('packageSasUri')]", "configurationUrl": "[parameters('configurationSasUri')]", "upgradeMode": "[parameters('upgradeMode')]", "roleProfile": { "roles": [ { "name": "WebRole1", "sku": { "name": "Standard_D1_v2", "capacity": "1" } }, { "name": "WorkerRole1", "sku": { "name": "Standard_D1_v2", "capacity": "1" } } ] }, "networkProfile": { "loadBalancerConfigurations": [ { "id": "[concat(variables('resourcePrefix'), 'Microsoft.Network/loadBalancers/', variables('lbName'))]", "name": "[variables('lbName')]", "properties": { "frontendIPConfigurations": [ { "name": "[variables('lbFEName')]", "properties": { "publicIPAddress": { "id": "[concat(variables('resourcePrefix'), 'Microsoft.Network/publicIPAddresses/', parameters('publicIPName'))]" } } } ] } } ] }, "osProfile": { "secrets": [ { "sourceVault": { "id": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.KeyVault/vaults/{keyvault-name}" }, "vaultCertificates": [ { "certificateUrl": "https://{keyvault-name}.vault.azure.net:443/secrets/ContosoCertificate/{secret-id}" } ] } ] }, "extensionProfile": { "extensions": [ { "name": "RDPExtension", "properties": { "autoUpgradeMinorVersion": true, "publisher": "Microsoft.Windows.Azure.Extensions", "type": "RDP", "typeHandlerVersion": "1.2.1", "settings": "<PublicConfig>\r\n <UserName>[Insert Username]</UserName>\r\n <Expiration>1/21/2022 12:00:00 AM</Expiration>\r\n</PublicConfig>", "protectedSettings": "<PrivateConfig>\r\n <Password>[Insert Password]</Password>\r\n</PrivateConfig>" } }, { "name": "Microsoft.Insights.VMDiagnosticsSettings_WebRole1", "properties": { "autoUpgradeMinorVersion": true, "publisher": "Microsoft.Azure.Diagnostics", "type": "PaaSDiagnostics", "typeHandlerVersion": "1.5", "settings": "[parameters('wadPublicConfig_WebRole1')]", "protectedSettings": "[parameters('wadPrivateConfig_WebRole1')]", "rolesAppliedTo": [ "WebRole1" ] } } ] } } } ] }
Deploy the template and parameter file (defining parameters in template file) to create the Cloud Service (extended support) deployment. Please refer these sample templates as required.
New-AzResourceGroupDeployment -ResourceGroupName "ContosOrg" -TemplateFile "file path to your template file" -TemplateParameterFile "file path to your parameter file"
Next steps
- Review frequently asked questions for Cloud Services (extended support).
- Deploy a Cloud Service (extended support) using the Azure portal, PowerShell, Template or Visual Studio.
- Visit the Cloud Services (extended support) samples repository
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for