gitlab rest-api how to link job/pipeline to project schedules - gitlab-api

Most projects have many pipeline schedules, I can link jobs to pipelines and project but not to the pipeline schedule that initiated the job. I'm trying to create a simple status-wall with jobs in red/green and if you press it you rerun the schedule. Heavily inspired by: https://github.com/jan-molak/jenkins-build-monitor-plugin.
Below are pipeline schedules for a project:
{
"project_id": "1518",
"schedules": [
{
"id": 411,
"description": "qa-04 provision users for demo",
"ref": "test1-20210318",
"cron": "6 18 * * *",
"cron_timezone": "Europe/Copenhagen",
"next_run_at": "2021-06-22T16:10:00.000Z",
"active": true,
"created_at": "2020-10-28T08:06:49.012Z",
"updated_at": "2021-06-21T16:10:10.107Z",
"owner": {..}
},
{
"id": 410,
"description": "test12 Demo fido2 solution fullstack test",
"ref": "master",
"cron": "40 06 * * *",
"cron_timezone": "Europe/Copenhagen",
"next_run_at": "2021-06-23T04:45:00.000Z",
"active": true,
"created_at": "2020-10-27T14:32:07.156Z",
"updated_at": "2021-06-22T04:45:29.164Z",
"owner": {..}
},
{
"id": 409,
"description": "test1 Demo fido2 solution fullstack test",
"ref": "master",
"cron": "05 04 * * *",
"cron_timezone": "Europe/Copenhagen",
"next_run_at": "2021-06-23T02:10:00.000Z",
"active": true,
"created_at": "2020-10-27T13:36:09.062Z",
"updated_at": "2021-06-22T02:10:34.070Z",
"owner": {..}
}
]
}
And here is a job executed by pipeline, but not by which schedule_id:
"project_id": "1518",
"jobs": [
{
"id": 3549568,
"status": "failed",
"stage": "test",
"name": "test12",
"ref": "master",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2021-06-22T04:45:31.465Z",
"started_at": "2021-06-22T04:45:33.354Z",
"finished_at": "2021-06-22T05:00:03.734Z",
"duration": 870.37944,
"queued_duration": 1.029369,
"user": {..},
"commit": {..},
"pipeline": {
"id": 489545,
"project_id": 1518,
"sha": "673073d3987fea3bb30a9433e15612712795c2cb",
"ref": "master",
"status": "failed",
"created_at": "2021-06-22T04:45:31.360Z",
"updated_at": "2021-06-22T05:00:03.874Z",
"web_url": "<url>/demo/demo-fullstack-test/-/pipelines/489545"
},
"web_url": "..",
"artifacts_file": {..},
"artifacts": [..],
"runner": {..},
"artifacts_expire_at": "2021-06-29T05:00:02.126Z",
"tag_list": [ ]
},
I can try to match the scheduler description with the name in the job, or try to check the job started_at with what that can match the crontab. Is there any other gitlab api that show this mapping I may have overseen.

The API was enhanced in Gitlab 15.3 to support this:
https://docs.gitlab.com/ee/api/pipeline_schedules.html#get-all-pipelines-triggered-by-a-pipeline-schedule

Related

Change web app .NET framework version with ARM template

I'm updating an existing web app to .NET 5. There is an ARM template that describes the web app configuration.
In the ARM template I have added
"netFrameworkVersion": "v5.0",
inside the Microsoft.Web/sites/config properties object.
The ARM template deployment succeeds, but the web app configuration is not changed from .NET Core 3.1 to .NET 5.
Oddly, when I look at the Azure Resource manager, it does contain the net netFrameworkVersion value.
This configuration is what I'm trying to change to .NET 5:
Am I missing a setting, or is it not possible to update the .NET version using an ARM template?
The answer for me was setting the property netFrameworkVersion to v6.0. No other change was necessary.
This is the partial ARM template, the section changed:
{
"name": "[parameters('webSiteName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2019-08-01",
"location": "[parameters('location')]",
"tags": {
"[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]": "empty"
},
"dependsOn": [
"[variables('hostingPlanName')]",
"[variables('appInsightsName')]"
],
"properties": {
"name": "[parameters('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(resourceId('Microsoft.Insights/components/', variables('appInsightsName')), '2020-02-02-preview').InstrumentationKey]"
},
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2020-02-02-preview').ConnectionString]"
}
],
"connectionStrings": [
{
"name": "DefaultConnection",
"connectionString": "[concat('Data Source=tcp:', reference(resourceId('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', parameters('databaseName'), ';User Id=', parameters('databaseUserLogin'), '#', reference(resourceId('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName, ';Password=', parameters('databaseUserPassword'), ';')]",
"type": "SQLAzure"
}
],
"ftpsState": "FtpsOnly",
"netFrameworkVersion": "v6.0"
},
"httpsOnly": true
}
}
You can find the full resource and ARM template at: https://github.com/feliperomero3/MoneySmart/blob/e2210eb6217eb6e06a299870acaf115d2e50c6a5/AzureResourceGroup/azuredeploy.json
Except for the netFrameworkVersion you need to change, also you need to add another resource to the resources in your template, just add it like below, it works fine on my side.
Note: It is for the web app whose OS is Windows.
{
"type": "Microsoft.Web/sites/config",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('webapp_name'), '/metadata')]",
"location": "Central US",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webapp_name'))]"
],
"properties": {
"CURRENT_STACK": "dotnet"
}
}
My complete sample:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webapp_name": {
"defaultValue": "joyweb11",
"type": "String"
},
"serviceplan_resourceid": {
"defaultValue": "/subscriptions/xxxxx/resourceGroups/xxxx/providers/Microsoft.Web/serverfarms/joyplan",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"name": "[parameters('webapp_name')]",
"location": "Central US",
"tags": {},
"kind": "app",
"properties": {
"enabled": true,
"hostNameSslStates": [
{
"name": "[concat(parameters('webapp_name'), '.azurewebsites.net')]",
"sslState": "Disabled",
"hostType": "Standard"
},
{
"name": "[concat(parameters('webapp_name'), '.scm.azurewebsites.net')]",
"sslState": "Disabled",
"hostType": "Repository"
}
],
"serverFarmId": "[parameters('serviceplan_resourceid')]",
"reserved": false,
"isXenon": false,
"hyperV": false,
"siteConfig": {},
"scmSiteAlsoStopped": false,
"clientAffinityEnabled": true,
"clientCertEnabled": false,
"hostNamesDisabled": false,
"containerSize": 0,
"dailyMemoryTimeQuota": 0,
"httpsOnly": false,
"redundancyMode": "None"
}
},
{
"type": "Microsoft.Web/sites/config",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('webapp_name'), '/web')]",
"location": "Central US",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webapp_name'))]"
],
"tags": {
},
"properties": {
"numberOfWorkers": 1,
"defaultDocuments": [
"Default.htm",
"Default.html",
"Default.asp",
"index.htm",
"index.html",
"iisstart.htm",
"default.aspx",
"index.php",
"hostingstart.html"
],
"netFrameworkVersion": "v5.0",
"requestTracingEnabled": false,
"remoteDebuggingEnabled": false,
"remoteDebuggingVersion": "VS2019",
"httpLoggingEnabled": false,
"logsDirectorySizeLimit": 35,
"detailedErrorLoggingEnabled": false,
"publishingUsername": "$joyweb11",
"azureStorageAccounts": {},
"scmType": "None",
"use32BitWorkerProcess": true,
"webSocketsEnabled": false,
"alwaysOn": true,
"managedPipelineMode": "Integrated",
"virtualApplications": [
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot",
"preloadEnabled": true
}
],
"loadBalancing": "LeastRequests",
"experiments": {
"rampUpRules": []
},
"autoHealEnabled": false,
"localMySqlEnabled": false,
"ipSecurityRestrictions": [
{
"ipAddress": "Any",
"action": "Allow",
"priority": 1,
"name": "Allow all",
"description": "Allow all access"
}
],
"scmIpSecurityRestrictions": [
{
"ipAddress": "Any",
"action": "Allow",
"priority": 1,
"name": "Allow all",
"description": "Allow all access"
}
],
"scmIpSecurityRestrictionsUseMain": false,
"http20Enabled": false,
"minTlsVersion": "1.2",
"ftpsState": "AllAllowed",
"reservedInstanceCount": 0
}
},
{
"type": "Microsoft.Web/sites/hostNameBindings",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('webapp_name'), '/', parameters('webapp_name'), '.azurewebsites.net')]",
"location": "Central US",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webapp_name'))]"
],
"properties": {
"siteName": "[parameters('webapp_name')]",
"hostNameType": "Verified"
}
},
{
"type": "Microsoft.Web/sites/config",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('webapp_name'), '/metadata')]",
"location": "Central US",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webapp_name'))]"
],
"properties": {
"CURRENT_STACK": "dotnet"
}
}
]
}

Not able to apply CMK encryption to Azure Storage Account through ARM Template

I am trying to attach CMK Encryption with Azure Storage Account through ARM Template but I am getting error as below. Need quick help with it. Able to apply it through portal after Storage Account is created but not able to do via ARM Template while creating Storage Account.
Error- [error]FeatureNotSupportedForAccount: Missing pre-requisites to enable EncryptionAtRest/Customer Managed Key for this storage account.
ARM:-
"resources": [
{​​​​​​​
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "[variables('storageaccountname')]",
"location": "[resourceGroup().location]",
"sku": {​​​​​​​
"name": "[parameters('storageaccountype')]"
}​​​​​​​,
"kind": "[parameters('storagekind')]",
"properties": {​​​​​​​
"supportsHttpsTrafficOnly": true,
"accesstier": "[parameters('accesstier')]",
"largeFileSharesState": "[parameters('largefilesharesstate')]",
"allowBlobPublicAccess": false,
"encryption": {​​​​​​​
"services": {​​​​​​​
"file": {​​​​​​​
"enabled": true
}​​​​​​​,
"blob": {​​​​​​​
"enabled": true
}​​​​​​​
}​​​​​​​,
"keySource": "Microsoft.Keyvault",
"keyvaultproperties": {​​​​​​​
"keyvaulturi": "[parameters('kvuri')]",
"keyname": "[parameters('keyname')]",
"keyversion": "[parameters('keyversion')]"
}​​​​​​​
}​​​​​​​
}​​​​​​​,
"tags": {​​​​​​​
"abcid": "[parameters('abcid')]"
}​​​​​​​
}​​​​​​​
According to the document, if you want to configure encryption with customer-managed keys stored in Azure key valt, we need to do the following steps
Create storage account and Enable Identity
Update Azure Key vault. Enable soft delete and purge protection.
Configure access policy for the storage account's Identity
Configure customer-managed keys for the storage account.
Regarding how to configure these with arm template, please refer to the following template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"keyName": {
"type": "string",
"defaultValue": ""
},
"keyVersion": {
"type": "string",
"defaultValue": ""
},
"vaultName": {
"defaultValue": "",
"type": "String"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"accountNmae": {
"type": "string",
"defaultValue": "tetsdfgfgdffd"
},
},
"variables": {},
"resources": [{
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"name": "[ parameters('accountNmae')]",
"apiVersion": "2019-06-01",
"location": "[ parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"supportsHttpsTrafficOnly": true
},
"dependsOn": []
}, {
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2016-10-01",
"name": "[parameters('vaultName')]",
"location": "eastasia",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('accountNmae'))]"
],
"properties": {
"sku": {
"family": "A",
"name": "Standard"
},
"tenantId": "[subscription().tenantid]",
"accessPolicies": [],
"enabledForDeployment": true,
"enabledForDiskEncryption": true,
"enabledForTemplateDeployment": true,
"enableSoftDelete": true
}
}, {
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-07-01",
"name": "updateStorageAccount",
"dependsOn": [
"[resourceId('Microsoft.KeyVault/vaults', parameters('vaultName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "0.1.0.0",
"resources": [{
"type": "Microsoft.KeyVault/vaults/accessPolicies",
"name": "[concat(parameters('vaultName'), '/add')]",
"apiVersion": "2019-09-01",
"properties": {
"accessPolicies": [{
"tenantId": "[subscription().tenantid]",
"objectId": "[reference(resourceId('Microsoft.Storage/storageAccounts', parameters('accountNmae')),'2019-06-01', 'full').identity.principalId]",
"permissions": {
"keys": [
"wrapkey",
"unwrapkey",
"get"
],
"secrets": [],
"certificates": []
}
}
]
}
}, {
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"name": "[parameters('accountNmae')]",
"apiVersion": "2019-06-01",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"encryption": {
"services": {
"file": {
"enabled": true
},
"blob": {
"enabled": true
}
},
"keySource": "Microsoft.Keyvault",
"keyvaultproperties": {
"keyvaulturi": "[reference(resourceId('Microsoft.KeyVault/vaults',parameters('vaultName')),'2016-10-01', 'full').properties.vaultUri]",
"keyname": "[parameters('keyName')]",
"keyversion": "[parameters('keyversion')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.KeyVault/vaults/accessPolicies', parameters('vaultName'), 'add')]"
]
}
]
}
}
}
]
}
For more details, please refer to the blog

Azure ARM template - run powershell script against VMs located in many different az regions

I have prepared ARM template for Windows VMs configuration. Code presented below. I tested this ARM template agains list of VMs located in the same region, and it worked as expected, deployment completed successfully. Problem is when I would like to run that code against VMs located in many az regions, is there any way to do it?
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "List of virtual machines to be reconfigured, if using multiple VMs, make their names comma separate. E.g. VM01, VM02, VM03."
},
"defaultValue": "VM1,VM2"
},
"Location": {
"type": "string",
"metadata": {
"description": "Location of the VM"
},
"defaultvalue": "WestEurope"
},
"customScriptFileToRun": {
"type": "string",
"metadata": {
"description": "Specify the name of the configuration script"
},
"defaultvalue": "script.ps1"
},
"secureFileUri": {
"type": "string",
"defaultValue": "xxxxxxx",
"metadata": {
"description": "Secure SAS blob URL"
}
},
"OMSWorkspaceResourceGroup": {
"type": "string",
"metadata": {
"description": "Log analytics workspace Resource Group"
},
"defaultvalue": "yourLogAnalyticsRG"
},
"omsWorkspacename": {
"type": "string",
"metadata": {
"description": "Log analytics workspace name"
},
"defaultvalue": "YourLoganalyticsworkspacename"
}
},
"variables": {
"vmListArray": "[split(parameters('vmName'),',')]",
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File', ' ', parameters('customScriptFileToRun'))]"
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2018-10-01",
"name": "[concat(trim(variables('vmListArray')[copyIndex()]),'/WindowsRegModyfication')]",
"copy": {
"name": "ExtentionLooptoAllVMs",
"count": "[length(variables('vmListArray'))]"
},
"location": "[parameters('Location')]",
"properties": {
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[parameters('secureFileUri')]"
],
"commandToExecute": "[variables('commandToExecute')]"
},
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"protectedSettings": {}
}
}
]
}
According to your need, we can define vmName and location as the parameter in Azure ARm template and use PowerShell get-AzVm to list all windows VM.
For example
My template.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "List of virtual machines to be reconfigured, if using multiple VMs, make their names comma separate. E.g. VM01, VM02, VM03."
}
},
"Location": {
"type": "string",
"metadata": {
"description": "Location of the VM"
}
},
"customScriptFileToRun": {
"type": "string",
"metadata": {
"description": "Specify the name of the configuration script"
},
"defaultvalue": "installWebServer.ps1"
},
"secureFileUri": {
"type": "string",
"defaultValue": "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorial-vm-extension/installWebServer.ps1",
"metadata": {
"description": "the file URL"
}
}
},
"variables": {
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File', ' ', parameters('customScriptFileToRun'))]"
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"name": "[parameters('vmName')]",
"location": "[parameters('Location')]",
"properties": {
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2019-07-01",
"name": "[concat( parameters('vmName'),'/WindowsRegModyfication')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
],
"location": "[parameters('Location')]",
"properties": {
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[parameters('secureFileUri')]"
],
"commandToExecute": "[variables('commandToExecute')]"
},
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"protectedSettings": {}
}
}
]
}
deploy
$vms=Get-AzVM | Where-Object {$_.StorageProfile.OsDisk.OsType -eq 'Windows'}
foreach($vm in $vms){
$TemplateObject=#{"vmName"=$vm.Name;"Location"=$vm.Location}
New-AzResourceGroupDeployment -ResourceGroupName $vm.ResourceGroupName -TemplateFile "E:\template.json" -TemplateParameterObject $TemplateObject -Debug
}

"The metric names were not found" when deploying microsoft.insights/metricAlerts

I'm trying to deploy a MetricAlert with my Traffic Manager Profile and I always get {
"Code": "BadRequest",
"Message": "The metric names were not found ."
}
I'm trying to use the Endpoint Status by Endpoint metric and having no luck. Any idea what the correct metric name would be or how I can find it?
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "microsoft.insights/metricAlerts",
"apiVersion": "2018-03-01",
"name": "All-PPE-Endpoints-Down",
"location": "global",
"tags": {
"displayName": "Alert-AllEndpointsDown"
},
"properties": {
"actions": [
{
"actionGroupId": "[resourceId('microsoft.insights/actionGroups', 'TDFFCEmailActionGroup')]"
}
],
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "DynamicThresholdCriterion",
"name": "1st criterion",
"metricName": "Endpoint Status by Endpoint(Platform)",
"dimensions": [],
"operator": "LessThan",
"alertSensitivity": "Medium",
"failingPeriods": {
"numberOfEvaluationPeriods": "4",
"minFailingPeriodsToAlert": "3"
},
"timeAggregation": "Maximum"
}
]
},
"description": "All endpoints are not responding to ping",
"enabled": true,
"evaluationFrequency": "PT5M",
"scopes": [
"/subscriptions/84eba200-00a9-41d3-9916-d63b2e25da02/resourceGroups/tdff5-rg-ppe/providers/Microsoft.Network/trafficManagerProfiles/tdfppegas"
],
"severity": 3,
"windowSize": "PT5M"
}
}
]
}
The metrics documentation webpage which describes all of the built-in metrics can be found here: https://learn.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftnetworktrafficmanagerprofiles
In this case, the key I was looking for was ProbeAgentCurrentEndpointStateByProfileResourceId

ARM Template.json Dynamic connectionstring

I have taken a deployment template from azure and added this to a deployment project in Visual Studio 2015. When the Resource Group is made and deployed, everything works well except for the Web Site connectionstrings.
I have TableStorage, DocumentDb, and Redis instances all being created by this and cannot figure out how to get the Primary Connection String and Primary Key of these items so that I don't have to go in by hand and add them.
looking at the ARM Template Functions ListKeys should do the trick, but after deployment the value is empty. Furthermore, trying a simple string (TestConnectionString) also adds the name, but not the value.
{
"type": "Microsoft.Web/sites",
"kind": "app",
"name": "[parameters('WebAppName')]",
"apiVersion": "2015-08-01",
"properties": {
"name": "[parameters('WebAppName')]",
"resources": [],
"siteConfig": {
"connectionstrings": [
{
"name": "DocumentDbKey",
"value": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('docDbName')), '2015-11-06').primaryMasterKey]",
"type": "Custom"
},
{
"name": "TestConnectionString",
"value": "dummystring:pleaseignore;",
"type": "Custom"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('docDbName'))]",
]
}
As your description we can use ARM Template Functions ListKeys to get the Keys. And we could use the following template code to set the connection string. I test Azure storage connection string and Document DB key, It works correctly for me , please have a try. The following is my detail steps:
1.Create Basic Azure Resource Group project with template WebApp
2.From demo remove the unnecessary resource.
3.Add the connection string setting
"resources": [
{
"name": "connectionstrings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[concat('Microsoft.Web/sites/', variables('webSiteName'))]"
],
"tags": {
"displayName": "tomConnectionString"
},
"properties": {
"documentDB": {
"value": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', variables('docDbName')), '2015-11-06').primaryMasterKey]",
"type": "Custom"
},
"storage": {
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',concat(listKeys(variables('storageAccountId'),'2015-05-01-preview').key1))]",
"type": "Custom"
}
}
}
]
Add the corresponding parameters or variables such as storage info or docDbName
Deploy the Website
Check the result from the portal
Full template code:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"hostingPlanName": {
"type": "string",
"minLength": 1
},
"skuName": {
"type": "string",
"defaultValue": "S1",
"allowedValues": [
"F1",
"D1",
"B1",
"B2",
"B3",
"S1",
"S2",
"S3",
"P1",
"P2",
"P3",
"P4"
],
"metadata": {
"description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
}
},
"storageAccountName": {
"type": "string",
"metadata": {
"description": "Storage Account to access blob storage."
}
},
"skuCapacity": {
"type": "int",
"defaultValue": 1,
"minValue": 1,
"metadata": {
"description": "Describes plan's instance count"
}
}
},
"variables": {
"webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]",
"docDbName": "tomdocumentdb",
"storageAccountId": "[concat(resourceGroup().id,'/providers/Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "HostingPlan"
},
"sku": {
"name": "[parameters('skuName')]",
"capacity": "[parameters('skuCapacity')]"
},
"properties": {
"name": "[parameters('hostingPlanName')]"
}
},
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
"displayName": "Website"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
],
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
},
"resources": [
{
"name": "connectionstrings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[concat('Microsoft.Web/sites/', variables('webSiteName'))]"
],
"tags": {
"displayName": "tomConnectionString"
},
"properties": {
"documentDB": {
"value": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', variables('docDbName')), '2015-11-06').primaryMasterKey]",
"type": "Custom"
},
"storage": {
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',concat(listKeys(variables('storageAccountId'),'2015-05-01-preview').key1))]",
"type": "Custom"
}
}
}
]
}
]
}
Update:
We could get more useful info about ARM template from the azure resource.
I just had same problem, and it turns out the name of the property that holds the connection string should be named connectionString, so your siteConfig object should look like this:
"siteConfig": {
"connectionstrings": [
{
"name": "DocumentDbKey",
"connectionString": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('docDbName')), '2015-11-06').primaryMasterKey]",
"type": "Custom"
},
{
"name": "TestConnectionString",
"connectionString": "dummystring:pleaseignore;",
"type": "Custom"
}
]
}

Resources