Funzioni di distribuzione per i modelli di Azure Resource ManagerDeployment functions for Azure Resource Manager templates
Gestione risorse fornisce le funzioni seguenti per ottenere i valori dalle sezioni del modello e i valori relativi alla distribuzione:Resource Manager provides the following functions for getting values from sections of the template and values related to the deployment:
Per ottenere valori da risorse, gruppi di risorse o sottoscrizioni, vedere Funzioni delle risorse.To get values from resources, resource groups, or subscriptions, see Resource functions.
distribuzionedeployment
deployment()
Restituisce informazioni sull'operazione di distribuzione corrente.Returns information about the current deployment operation.
Valore restituitoReturn value
Questa funzione restituisce l'oggetto che viene passato durante la distribuzione.This function returns the object that is passed during deployment. Le proprietà nell'oggetto restituito variano a seconda che l'oggetto di distribuzione venga passato come un collegamento o come un oggetto inline.The properties in the returned object differ based on whether the deployment object is passed as a link or as an in-line object. Quando l'oggetto di distribuzione viene passato inline, ad esempio quando si usa il parametro -TemplateFile in Azure PowerShell per puntare a un file locale, l'oggetto restituito è nel formato seguente:When the deployment object is passed in-line, such as when using the -TemplateFile parameter in Azure PowerShell to point to a local file, the returned object has the following format:
{
"name": "",
"properties": {
"template": {
"$schema": "",
"contentVersion": "",
"parameters": {},
"variables": {},
"resources": [
],
"outputs": {}
},
"parameters": {},
"mode": "",
"provisioningState": ""
}
}
Quando l'oggetto viene passato come collegamento, come quando si usa il parametro -TemplateUri per puntare a un oggetto remoto, l'oggetto viene restituito nel formato seguente:When the object is passed as a link, such as when using the -TemplateUri parameter to point to a remote object, the object is returned in the following format:
{
"name": "",
"properties": {
"templateLink": {
"uri": ""
},
"template": {
"$schema": "",
"contentVersion": "",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {}
},
"parameters": {},
"mode": "",
"provisioningState": ""
}
}
OsservazioniRemarks
È possibile usare deployment() per il collegamento a un altro modello in base all'URI del modello padre.You can use deployment() to link to another template based on the URI of the parent template.
"variables": {
"sharedTemplateUrl": "[uri(deployment().properties.templateLink.uri, 'shared-resources.json')]"
}
EsempioExample
Il modello di esempio seguente restituisce l'oggetto di distribuzione:The following example template returns the deployment object:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"subscriptionOutput": {
"value": "[deployment()]",
"type" : "object"
}
}
}
L'esempio precedente restituisce l'oggetto seguente:The preceding example returns the following object:
{
"name": "deployment",
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"subscriptionOutput": {
"type": "Object",
"value": "[deployment()]"
}
}
},
"parameters": {},
"mode": "Incremental",
"provisioningState": "Accepted"
}
}
Per distribuire questo modello di esempio con l'interfaccia della riga di comando di Azure, usare:To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/deployment.json
Per distribuire questo modello di esempio con PowerShell, usare:To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/deployment.json
Parametriparameters
parameters(parameterName)
Restituisce un valore di parametro.Returns a parameter value. Il nome del parametro specificato deve essere definito nella sezione parameters del modello.The specified parameter name must be defined in the parameters section of the template.
ParametriParameters
ParametroParameter | ObbligatoriaRequired | typeType | DESCRIZIONEDescription |
---|---|---|---|
parameterNameparameterName | SìYes | stringastring | Nome del parametro da restituire.The name of the parameter to return. |
Valore restituitoReturn value
Il valore del parametro specificato.The value of the specified parameter.
OsservazioniRemarks
Per impostare i valori delle risorse, si usano in genere i parametri.Typically, you use parameters to set resource values. Nell'esempio seguente il nome del sito Web viene impostato sul valore del parametro passato durante la distribuzione.The following example sets the name of web site to the parameter value passed in during deployment.
"parameters": {
"siteName": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2016-08-01",
"name": "[parameters('siteName')]",
"type": "Microsoft.Web/Sites",
...
}
]
EsempioExample
Il modello di esempio seguente mostra un uso semplificato della funzione parameters.The following example template shows a simplified use of the parameters function.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"stringParameter": {
"type" : "string",
"defaultValue": "option 1"
},
"intParameter": {
"type": "int",
"defaultValue": 1
},
"objectParameter": {
"type": "object",
"defaultValue": {"one": "a", "two": "b"}
},
"arrayParameter": {
"type": "array",
"defaultValue": [1, 2, 3]
},
"crossParameter": {
"type": "string",
"defaultValue": "[parameters('stringParameter')]"
}
},
"variables": {},
"resources": [],
"outputs": {
"stringOutput": {
"value": "[parameters('stringParameter')]",
"type" : "string"
},
"intOutput": {
"value": "[parameters('intParameter')]",
"type" : "int"
},
"objectOutput": {
"value": "[parameters('objectParameter')]",
"type" : "object"
},
"arrayOutput": {
"value": "[parameters('arrayParameter')]",
"type" : "array"
},
"crossOutput": {
"value": "[parameters('crossParameter')]",
"type" : "string"
}
}
}
L'output dell'esempio precedente con i valori predefiniti è il seguente:The output from the preceding example with the default values is:
NOMEName | typeType | ValoreValue |
---|---|---|
stringOutputstringOutput | stringString | option 1option 1 |
intOutputintOutput | intInt | 11 |
objectOutputobjectOutput | OggettoObject | {"one": "a", "two": "b"}{"one": "a", "two": "b"} |
arrayOutputarrayOutput | ArrayArray | [1, 2, 3][1, 2, 3] |
crossOutputcrossOutput | stringString | option 1option 1 |
Per distribuire questo modello di esempio con l'interfaccia della riga di comando di Azure, usare:To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/parameters.json
Per distribuire questo modello di esempio con PowerShell, usare:To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/parameters.json
variablesvariables
variables(variableName)
Restituisce il valore della variabile.Returns the value of variable. Il nome della variabile specificato deve essere definito nella sezione variables del modello.The specified variable name must be defined in the variables section of the template.
ParametriParameters
ParametroParameter | ObbligatoriaRequired | typeType | DESCRIZIONEDescription |
---|---|---|---|
variableNamevariableName | SìYes | stringString | Nome della variabile da restituire.The name of the variable to return. |
Valore restituitoReturn value
Il valore della variabile specificata.The value of the specified variable.
OsservazioniRemarks
Per semplificare il modello creando valori complessi una sola volta, si usano in genere le variabili.Typically, you use variables to simplify your template by constructing complex values only once. Nell'esempio seguente viene creato un nome univoco per un account di archiviazione.The following example constructs a unique name for a storage account.
"variables": {
"storageName": "[concat('storage', uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageName')]",
...
},
{
"type": "Microsoft.Compute/virtualMachines",
"dependsOn": [
"[variables('storageName')]"
],
...
}
],
EsempioExample
Il modello di esempio seguente restituisce valori di variabile diversi.The following example template returns different variable values.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"var1": "myVariable",
"var2": [ 1,2,3,4 ],
"var3": "[ variables('var1') ]",
"var4": {
"property1": "value1",
"property2": "value2"
}
},
"resources": [],
"outputs": {
"exampleOutput1": {
"value": "[variables('var1')]",
"type" : "string"
},
"exampleOutput2": {
"value": "[variables('var2')]",
"type" : "array"
},
"exampleOutput3": {
"value": "[variables('var3')]",
"type" : "string"
},
"exampleOutput4": {
"value": "[variables('var4')]",
"type" : "object"
}
}
}
L'output dell'esempio precedente con i valori predefiniti è il seguente:The output from the preceding example with the default values is:
NOMEName | typeType | ValoreValue |
---|---|---|
exampleOutput1exampleOutput1 | stringString | myVariablemyVariable |
exampleOutput2exampleOutput2 | ArrayArray | [1, 2, 3, 4][1, 2, 3, 4] |
exampleOutput3exampleOutput3 | stringString | myVariablemyVariable |
exampleOutput4exampleOutput4 | OggettoObject | {"property1": "value1", "property2": "value2"}{"property1": "value1", "property2": "value2"} |
Per distribuire questo modello di esempio con l'interfaccia della riga di comando di Azure, usare:To deploy this example template with Azure CLI, use:
az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/variables.json
Per distribuire questo modello di esempio con PowerShell, usare:To deploy this example template with PowerShell, use:
New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/variables.json
Passaggi successiviNext steps
- Per una descrizione delle sezioni in un modello di Azure Resource Manager, vedere Creazione di modelli di Azure Resource Manager.For a description of the sections in an Azure Resource Manager template, see Authoring Azure Resource Manager templates.
- Per unire più modelli, vedere Uso di modelli collegati con Azure Resource Manager.To merge multiple templates, see Using linked templates with Azure Resource Manager.
- Per eseguire un'iterazione di un numero di volte specificato durante la creazione di un tipo di risorsa, vedere Creare più istanze di risorse in Gestione risorse di Azure.To iterate a specified number of times when creating a type of resource, see Create multiple instances of resources in Azure Resource Manager.
- Per informazioni su come distribuire il modello che è stato creato, vedere Distribuire un'applicazione con un modello di Azure Resource Manager.To see how to deploy the template you have created, see Deploy an application with Azure Resource Manager template.