As part of our template files, we have a variable defined partially by deployment method's deployment().name, similar to this:
"myVariable": "[concat(SOME_CUSTOM_STRING_HERE, deployment().name)]"
The variable is then used as the deployment label for our Classic Cloud Service resources which includes the build number.
{
"apiVersion": "2015-12-01",
"type": "deploymentSlots",
"name": "staging",
"properties": {
"deploymentLabel": "[variables('myVariable')]",
...
},
...
}
Perhaps deployment().name can be set and not defined by Azure, but I haven't been able I haven't been able to find it.
However, the variable's value is different under Cloud Service Extended Support. This time the value is a long hash and the name of the Cloud Service resource, even thought the definition remains as shown above. The variable is used in a tag:
{
"apiVersion": "2021-03-01",
"type": "Microsoft.Compute/cloudServices",
"name": "RESOURCE_NAME",
"location": "[LOCATION]",
"tags": {
"DeploymentLabel": "[variables('myVariable')]",
...
},
...
}
So did the value of deployment().name template function change for deployments of Extended Support version of cloud service? If not, can it be set and how?
From the Azure Devops side, if you are running the deployment the task itself has the deployment name like deployment mode. if its not provided, automatically it gets generated
deploymentMode: 'Incremental'
deploymentName: 'deploymentname'
if its powershell then please check the link below
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-cli#azure-deployment-template-name
you set the name when you deploy a resource:
{
"apiVersion": "2021-03-01",
"type": "Microsoft.Compute/cloudServices",
"NAME": "MYRESOURCE",
"location": "[LOCATION]",
"tags": {
"DeploymentLabel": "[variables('myVariable')]",
...
},
...
}
Related
I am trying to create an ARM template for my runbook with additional variables ab packages.
I want to have the values of Automation Account Variables as parameters of ARM template.
When I am using the documentation syntax I am getting the variables value as "[parameters(parameterName)] instead the value of the parameter
when I am not using the syntax code I just get this error:
Invalid JSON - Kindly check the value of the variable
This is the ARM template resource code:
{
"apiVersion": "2020-01-13-preview",
"type": "Microsoft.Automation/automationAccounts/variables",
"name": "[concat(parameters('AutomationAccount'), '/blobContainerName')]",
"location": "[parameters('automationRegion')]",
"properties": {
"description": "output container name",
"isEncrypted": false,
"value": "\"[parameters('blobContainerName')]\""
}
}
how its looks like in the variables after deployment:
Try the following:
"properties": {
"value": "[concat('\"', parameters('blobContainerName'), '\"')]"
},
You need to use concat to join the strings
When I deploy in Azure DevOps the ARM template below I get an error due to an integer was expected, but a string was found. If I explicitly change the variables to values it will be properly picked up. Any idea what is going on here?
I have a Release Pipeline which deploys an ARM Template with parameters (not working, found string but integer was expected):
This works since I changed the variable values to explicit integers (working, but I want to use variable groups):
In the variable groups I have defined the name and values as:
FaultDomains 2
UpdateDomains 5
ARM Template:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "0.0.1.0",
"parameters": {
"AvailabilitySetName": {
"type": "string"
},
"FaultDomains": {
"type": "int"
},
"UpdateDomains": {
"type": "int"
}
},
"resources": [
{
"apiVersion": "2016-04-30-preview",
"type": "Microsoft.Compute/availabilitySets",
"name": "[parameters('AvailabilitySetName')]",
"location": "[resourceGroup().location]",
"properties": {
"platformUpdateDomainCount": "[parameters('UpdateDomains')]",
"platformFaultDomainCount": "[parameters('FaultDomains')]"
},
"sku": {
"name": "Aligned"
}
}
]
}
I tried to recreate the case and was able to deploy the availabilty set with given template using release pipeline,
Parameters
and make sure the parameteres are defined in the release variables.
NOTE: I used ARM TEMPLATE DEPLOYMENT task for deployment
deployment results
I discovered something, and I think it's a bug in ARM templates.
I have a template that creates an app service, and creates a deployment slot. Now I wanted to make sure that the deployment slot cloned the appsettings from the parent app service, so I used the cloningInfo node to set the source app service for the clone. But once I did that, setting the user defined managed identity on the deployment slot stopped working, while it is present in the template. My (simplified) template:
resources: [
{
"apiVersion": "2018-11-01",
"name": "MyAppservice",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"kind": "app",
"identity": {
"type": "userAssigned",
"userAssignedIdentities": {
"<some id>": {}
}
}
},
{
"type": "Microsoft.Web/sites/slots",
"apiVersion": "2018-11-01",
"name": "['MyAppservice','/secondslot')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', 'MyAppservice')]"
],
"kind": "app",
"identity": {
"type": "userAssigned",
"userAssignedIdentities": {
"<some id>": {}
},
"properties": {
"cloningInfo": {
"sourceWebAppId": "[resourceId('Microsoft.Web/sites', 'MyAppservice')]"
}
}
}
]
So when I deploy a template using the above basis, the user defined managed identity is not set on the deployment slot. When I remove the cloningInfo property, the user defined managed identity IS set, but the app settings of the parent app service are not copied.
Am I doing someting wrong here or is this a bug? I know that (for some reason) it is by design that use defined managed identities are not copied to deployment slots, so I would assume that when setting it manually while cloning from an existing app service, the cloning setting would not overwrite the user defined managed identity.
It's acknowledged that this is an issue currently where if cloning Info set, it's ignoring rest of the payload. Until it's fixed, workaround is to have 2 separate updates (one for cloning and one for MSI).
I'm trying to deploy simple resource group to Azure with ARM template. It consist of single virtual machine with public IP and nsg allowing accessing it via SSH. To secure access I'm setting admin user and password for VM, which are passed to template with parameters json. VM definition looks like this:
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-10-01",
"name": "[variables('vmName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
// ...
},
// ...
}
According to Azure quickstart templates repository for generating password I can use GEN-PASSWORD placeholder and GEN-UNIQUE to get unique alphanumeric string. That's why my parameters json looks like this:
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
// ...
"adminUsername": {
"value": "GEN_UNIQUE"
},
"adminPassword": {
"value": "GEN_PASSWORD"
}
}
}
However, whenever I try to deploy it (via Azure DevOps Pipeline) I got error that password is invalid:
2020-06-29T21:27:40.5401781Z ##[error]At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.
2020-06-29T21:27:40.5416217Z ##[error]Details:
2020-06-29T21:27:40.5419655Z ##[error]InvalidParameter: The supplied password must be between 6-72 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
Can anyone help? I tried to find more info about these placeholders, but Azure GitHub repository that I linked above seems to be the only source.
The GEN* values are special placeholders that only work in the context of the Azure Resource Manager QuickStart Templates repository and its automated template validation.
I am afraid you cannot use these placeholders in your own custom Azure DevOps pipelines.
Not sure if it is supported in ARM. I could find power-shell references only.
You cannot currently deploy a dacpac with an ARM template. The link above uses PowerShell but not ARM. You can create however create a database from a source database as a copy using an ARM template.
A simple way to find an example template for any Azure action is to perform the action in the portal - in this case, copy a database - and then open the appropriate resource group blade in the portal, list the deployments, locate the deployment just submitted and open it. Then select ViewTemplate from the menu bar and examine both the Template tab and the Parameters tab. These show you the full template and the parameter values actually used. You can then download the template, with accompanying Powershell script.
For database copy, here is the template:
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"databaseName": {
"type": "string"
},
"serverName": {
"type": "string"
},
"location": {
"type": "string"
},
"createMode": {
"type": "string"
},
"sourceDatabaseId": {
"type": "string"
},
"requestedServiceObjectiveName": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2014-04-01-preview",
"location": "[parameters('location')]",
"name": "[concat(parameters('serverName'), '/', parameters('databaseName'))]",
"properties": {
"createMode": "[parameters('createMode')]",
"sourceDatabaseId": "[parameters('sourceDatabaseId')]",
"requestedServiceObjectiveName": "[parameters('requestedServiceObjectiveName')]"
},
"type": "Microsoft.Sql/servers/databases"
}
]
}
For database copy createMode = 'Copy'
And be sure to provide a fully qualified resourceId formatted as follows:
"/subscriptions/<sub-id>/resourceGroups/<resourceGroupName>/providers/Microsoft.Sql/Servers/<server-name>/databases/<database-name>"
Make sure the resource group name capitalization is correct and that the server name is all lower case.
You can use the sourceDatabaseId property to reference another database. Then you can specify various createModes depending on what type of database you would like to create:
{
"properties": {
"createMode": "OnlineSecondary",
"sourceDatabaseId": "[resourceId('Microsoft.Sql/servers/databases', variables('sql01Name'), 'databasename')]"
}
}
http://msdn.microsoft.com/en-us/library/azure/mt163685.aspx
The answer above from #Bill Gibson - MSFT works if you are using a Microsoft.Sql/servers resource, however if you're using a Microsoft.Sql/managedInstances resource you'll need to use the appropriate Microsoft.Sql/managedInstance/databases - ARM Template.
The following works for me to perform a PointInTimeRestore accessing a source database that lives in another resource group (the variables and parameters are left as an exercise to the reader):
{
"type": "Microsoft.Sql/managedInstances/databases",
"name": "[concat(variables('destinationSqlManagedInstanceName'), '/', 'AdventureWorks')]",
"apiVersion": "2021-11-01",
"location": "[parameters('location')]",
"properties": {
"createMode": "PointInTimeRestore",
"restorePointInTime": "2022-12-14T12:00:00Z",
"sourceDatabaseId": "[resourceId(variables('sourceResourceGroupName'), 'Microsoft.Sql/managedInstances/databases', variables('sourceSqlManagedInstanceName'), 'AdventureWorks')]"
}
}
The documentation is broken in a few ways:
When attempting to perform a PointInTimeRestore the properties referenced (SourceDatabaseName, SourceManagedInstanceName, PointInTime) do not exist. Rather the following properties are used: restorePointInTime and sourceDatabaseId which are documented in the documentation.
Additionally, the restorePointInTime indicates that the time should be in ISO8601 format, however this is not the same as what is returned by utcNow(). Testing has shown that you must provide it in this version of the ISO8601 format: yyyy-MM-ddTHH:mm:ssZ which can be done using utcNow('yyyy-MM-ddTHH:mm:ssZ').
I have created an issue to try and get the documentation fixed up here: https://github.com/MicrosoftDocs/azure-docs/issues/102717