POST https://management.azure.com/providers/Microsoft.Resources/calculateTemplateHash?api-version=2025-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"
}
}
}
import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.serializer.SerializerEncoding;
import java.io.IOException;
/**
* Samples for Deployments CalculateTemplateHash.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/resources/resource-manager/Microsoft.Resources/deployments/stable/2025-04-01/examples/
* CalculateTemplateHash.json
*/
/**
* Sample code: Calculate template hash.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void calculateTemplateHash(com.azure.resourcemanager.AzureResourceManager azure) throws IOException {
azure.genericResources().manager().deploymentClient().getDeployments()
.calculateTemplateHashWithResponse(SerializerFactory.createDefaultManagementSerializerAdapter().deserialize(
"{\"$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\"}}",
Object.class, SerializerEncoding.JSON), com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource.deployments import DeploymentsMgmtClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-resource-deployments
# USAGE
python calculate_template_hash.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = DeploymentsMgmtClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.deployments.calculate_template_hash(
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",
},
},
)
print(response)
# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/deployments/stable/2025-04-01/examples/CalculateTemplateHash.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armdeployments_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeployments"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/edacc3b43f9603efa119eabb6013d952d1dbe7d6/specification/resources/resource-manager/Microsoft.Resources/deployments/stable/2025-04-01/examples/CalculateTemplateHash.json
func ExampleClient_CalculateTemplateHash() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armdeployments.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewClient().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 = armdeployments.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 { DeploymentsClient } = require("@azure/arm-resourcesdeployments");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/deployments/stable/2025-04-01/examples/CalculateTemplateHash.json
*/
async function calculateTemplateHash() {
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 DeploymentsClient(credential);
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