POST https://management.azure.com/providers/Microsoft.Resources/calculateTemplateHash?api-version=2021-04-01
{
"$schema": "http://schemas.management.azure.com/deploymentTemplate?api-version=2014-04-01-preview",
"contentVersion": "1.0.0.0",
"parameters": {
"string": {
"type": "string"
}
},
"variables": {
"string": "string",
"int": 42,
"bool": true,
"array": [
1,
2,
3,
4
],
"object": {
"object": {
"vmSize": "Large",
"location": "West US"
}
}
},
"resources": [],
"outputs": {
"string": {
"type": "string",
"value": "myvalue"
}
}
}
package armresources_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/4fd842fb73656039ec94ce367bcedee25a57bd18/specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/examples/CalculateTemplateHash.json
func ExampleDeploymentsClient_CalculateTemplateHash() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresources.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewDeploymentsClient().CalculateTemplateHash(ctx, map[string]any{
"$schema": "http://schemas.management.azure.com/deploymentTemplate?api-version=2014-04-01-preview",
"contentVersion": "1.0.0.0",
"outputs": map[string]any{
"string": map[string]any{
"type": "string",
"value": "myvalue",
},
},
"parameters": map[string]any{
"string": map[string]any{
"type": "string",
},
},
"resources": []any{},
"variables": map[string]any{
"array": []any{
float64(1),
float64(2),
float64(3),
float64(4),
},
"bool": true,
"int": float64(42),
"object": map[string]any{
"object": map[string]any{
"location": "West US",
"vmSize": "Large",
},
},
"string": "string",
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.TemplateHashResult = armresources.TemplateHashResult{
// MinifiedTemplate: to.Ptr("{\"$SCHEMA\":\"HTTP://SCHEMAS.MANAGEMENT.AZURE.COM/DEPLOYMENTTEMPLATE?API-VERSION=2014-04-01-PREVIEW\",\"CONTENTVERSION\":\"1.0.0.0\",\"PARAMETERS\":{\"STRING\":{\"TYPE\":\"STRING\"}},\"VARIABLES\":{\"STRING\":\"STRING\",\"INT\":42,\"BOOL\":TRUE,\"ARRAY\":[1,2,3,4],\"OBJECT\":{\"OBJECT\":{\"VMSIZE\":\"LARGE\",\"LOCATION\":\"WEST US\"}}},\"RESOURCES\":[],\"OUTPUTS\":{\"STRING\":{\"TYPE\":\"STRING\",\"VALUE\":\"MYVALUE\"}}}"),
// TemplateHash: to.Ptr("695440707931307747"),
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceManagementClient } = require("@azure/arm-resources");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Calculate the hash of the given template.
*
* @summary Calculate the hash of the given template.
* x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/examples/CalculateTemplateHash.json
*/
async function calculateTemplateHash() {
const subscriptionId =
process.env["RESOURCES_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const template = {
$schema:
"http://schemas.management.azure.com/deploymentTemplate?api-version=2014-04-01-preview",
contentVersion: "1.0.0.0",
outputs: { string: { type: "string", value: "myvalue" } },
parameters: { string: { type: "string" } },
resources: [],
variables: {
array: [1, 2, 3, 4],
bool: true,
int: 42,
object: { object: { location: "West US", vmSize: "Large" } },
string: "string",
},
};
const credential = new DefaultAzureCredential();
const client = new ResourceManagementClient(credential, subscriptionId);
const result = await client.deployments.calculateTemplateHash(template);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
// Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/examples/CalculateTemplateHash.json
// this example is just showing the usage of "Deployments_CalculateTemplateHash" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this TenantResource created on azure
// for more information of creating TenantResource, please refer to the document of TenantResource
var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current;
// invoke the operation
BinaryData template = BinaryData.FromObjectAsJson(new Dictionary<string, object>()
{
["$schema"] = "http://schemas.management.azure.com/deploymentTemplate?api-version=2014-04-01-preview",
["contentVersion"] = "1.0.0.0",
["outputs"] = new Dictionary<string, object>()
{
["string"] = new Dictionary<string, object>()
{
["type"] = "string",
["value"] = "myvalue"
}
},
["parameters"] = new Dictionary<string, object>()
{
["string"] = new Dictionary<string, object>()
{
["type"] = "string"
}
},
["resources"] = new object[] { },
["variables"] = new Dictionary<string, object>()
{
["array"] = new object[] { "1", "2", "3", "4" },
["bool"] = "true",
["int"] = "42",
["object"] = new Dictionary<string, object>()
{
["object"] = new Dictionary<string, object>()
{
["location"] = "West US",
["vmSize"] = "Large"
}
},
["string"] = "string"
}
});
TemplateHashResult result = await tenantResource.CalculateDeploymentTemplateHashAsync(template);
Console.WriteLine($"Succeeded: {result}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue