{"id":1793,"date":"2011-04-01T13:57:33","date_gmt":"2001-01-01T01:00:00","guid":{"rendered":"http:\/\/inswwdev.azurewebsites.net\/au\/insights\/uncategorized\/automatically-naming-resources-in-an-azure-resource-management-template\/"},"modified":"2024-09-11T08:26:20","modified_gmt":"2024-09-11T08:26:20","slug":"automatically-naming-resources-in-an-azure-resource-management-template","status":"publish","type":"post","link":"https:\/\/www.insentragroup.com\/au\/insights\/geek-speak\/cloud-and-modern-data-center\/automatically-naming-resources-in-an-azure-resource-management-template\/","title":{"rendered":"Automatically Naming Resources in an Azure Resource Management Template"},"content":{"rendered":"<h3 style=\"padding-bottom: 15px; margin-bottom: 30px; margin-top: 40px; border-bottom: 1px solid #f16020;\">Why?<\/h3>\n<p style=\"text-align: justify;\">Resource templates are a great concept, but are fraught with danger. Badly named resources and naming inconsistency across resources in different subscriptions can make it difficult to determine purpose.<\/p>\n<p style=\"text-align: justify;\">If a resource such as a Virtual Network or a Storage Account is badly named in a resource template file, you may find that you have to rely on the icon pictures in the Azure portal to indicate what type of resources you are looking at.<\/p>\n<p style=\"text-align: justify;\">What if you need to see at a glance:<\/p>\n<ul>\n<li>What region the resource belongs to i.e. Australia East or Australia Southeast?<\/li>\n<li>What environment the resource belongs to i.e. Production or Testing?<\/li>\n<li>What type of resource it is?<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">The problem comes from trying to keep the names meaningful and consistent. How do you ensure that your naming standards are adhered to?<\/p>\n<h3 style=\"padding-bottom: 15px; margin-bottom: 30px; margin-top: 40px; border-bottom: 1px solid #f16020;\">Scenario<\/h3>\n<p style=\"text-align: justify;\">In my case I would like to name resources as follows:<\/p>\n<pre><span>&lt;Resource Prefix&gt;_&lt;Environment&gt;_&lt;Location&gt;<\/span><\/pre>\n<p style=\"text-align: justify;\">For instance:<\/p>\n<pre><span>\"Vnet_Prod_auSoutheast\"<\/span>  <span id=\"more-756\"><\/span><\/pre>\n<h3 style=\"padding-bottom: 15px; margin-bottom: 30px; margin-top: 40px; border-bottom: 1px solid #f16020;\">Solution<\/h3>\n<p style=\"text-align: justify;\">Create new parameters (under the parameters section) in the main JSON (AzureDeploy.json) file for:<\/p>\n<ul>\n<li>Current location (i.e. \u201cAustralia East\u201d)<\/li>\n<li>Short form of the location (i.e. \u201cauEast\u201d)<\/li>\n<li>Environment (i.e. \u201cProd\u201d or \u201cTesting\u201d)<\/li>\n<\/ul>\n<div>\n<div id=\"highlighter_886380\" class=\"syntaxhighlighter  jscript\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<div class=\"line number20 index19 alt1\">20<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\">&#8220;location&#8221; : {<\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number3 index2 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;allowedValues&#8221; : [&#8220;Australia East&#8221;, &#8220;Australia Southeast&#8221;],<\/div>\n<div class=\"line number4 index3 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number5 index4 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;Deployment location&#8221;<\/div>\n<div class=\"line number6 index5 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<div class=\"line number7 index6 alt2\">},<\/div>\n<div class=\"line number8 index7 alt1\">&#8220;shortlocation&#8221; : {<\/div>\n<div class=\"line number9 index8 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number10 index9 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;defaultValue&#8221; : &#8220;[replace(resourceGroup().location,&#8217;australia&#8217;,&#8217;au&#8217;)]&#8221;,<\/div>\n<div class=\"line number11 index10 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number12 index11 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;Short Deployment location&#8221;<\/div>\n<div class=\"line number13 index12 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<div class=\"line number14 index13 alt1\">},<\/div>\n<div class=\"line number15 index14 alt2\">&#8220;Environment&#8221; : {<\/div>\n<div class=\"line number16 index15 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number17 index16 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;allowedValues&#8221; : [&#8220;Prod&#8221;, &#8220;Testing&#8221;],<\/div>\n<div class=\"line number18 index17 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number19 index18 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;Production or Testing&#8221;<\/div>\n<div class=\"line number20 index19 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"text-align: justify;\">Create additional parameters (under the parameters section) in the main JSON file to define the naming convention prefixes (In this case for Virtual Networks and Subnets):<\/p>\n<div>\n<div id=\"highlighter_404093\" class=\"syntaxhighlighter  jscript\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\">&#8220;VNETNamingStandard&#8221; : {<\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number3 index2 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;defaultValue&#8221; : &#8220;VNet_&#8221;,<\/div>\n<div class=\"line number4 index3 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number5 index4 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;VNet Naming Standard&#8221;<\/div>\n<div class=\"line number6 index5 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<div class=\"line number7 index6 alt2\">},<\/div>\n<div class=\"line number8 index7 alt1\">&#8220;SubnetNamingStandard&#8221; : {<\/div>\n<div class=\"line number9 index8 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number10 index9 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;defaultValue&#8221; : &#8220;Subnet_&#8221;,<\/div>\n<div class=\"line number11 index10 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number12 index11 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;Subnet Naming Standard&#8221;<\/div>\n<div class=\"line number13 index12 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<div class=\"line number14 index13 alt1\">}<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"text-align: justify;\">Use the \u2018Concat\u2019 command in the main JSON file (under the parameters section) to create new standardized names by concatenating the prefix, environment and short location :<\/p>\n<div>\n<div id=\"highlighter_961483\" class=\"syntaxhighlighter  jscript\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\">&#8220;vnetName&#8221; : {<\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number3 index2 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;defaultValue&#8221; :<\/div>\n<div class=\"line number4 index3 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;[concat(parameters(&#8216;VNetNamingStandard&#8217;),parameters(&#8216;Environment&#8217;),&#8217;_&#8217;,&nbsp; parameters(&#8216;shortlocation&#8217;))]&#8221;,<\/div>\n<div class=\"line number5 index4 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number6 index5 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;VNet name&#8221;<\/div>\n<div class=\"line number7 index6 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<div class=\"line number8 index7 alt1\">},<\/div>\n<div class=\"line number9 index8 alt2\">&#8220;SubnetName&#8221; : {<\/div>\n<div class=\"line number10 index9 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number11 index10 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;defaultValue&#8221; :<\/div>\n<div class=\"line number12 index11 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;[concat(parameters(&#8216;SubnetNamingStandard&#8217;),parameters(&#8216;Environment&#8217;),&#8217;_&#8217;,&nbsp; parameters(&#8216;shortlocation&#8217;))]&#8221;,<\/div>\n<div class=\"line number13 index12 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number14 index13 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;Subnet name&#8221;<\/div>\n<div class=\"line number15 index14 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<div class=\"line number16 index15 alt1\">}<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"text-align: justify;\">For Storage accounts it\u2019s a little trickier. They have to be lowercase.<\/p>\n<div>\n<div id=\"highlighter_737438\" class=\"syntaxhighlighter  jscript\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\">&#8220;StorageName&#8221; : {<\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;type&#8221; : &#8220;string&#8221;,<\/div>\n<div class=\"line number3 index2 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;defaultValue&#8221; : &#8220;[concat(tolower(parameters(&#8216;StorageNamingStandard&#8217;)),tolower(parameters(&#8216;Environment&#8217;)),tolower(parameters(&#8216;shortlocation&#8217;)))]&#8221;,<\/div>\n<div class=\"line number4 index3 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;&#8220;metadata&#8221; : {<\/div>\n<div class=\"line number5 index4 alt2\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;description&#8221; : &#8220;Storage Name&#8221;<\/div>\n<div class=\"line number6 index5 alt1\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div>\n<div class=\"line number7 index6 alt2\">}<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p style=\"text-align: justify;\">Note: There maybe a better way to make the whole string lower case, I haven\u2019t found it yet!<\/p>\n<h3 style=\"padding-bottom: 15px; margin-bottom: 30px; margin-top: 40px; border-bottom: 1px solid #f16020;\">Parameters JSON file vs Main Deployment JSON file<\/h3>\n<p style=\"text-align: justify;\">I advise that the above is placed into the primary<span>&nbsp;<\/span><em>azuredeploy.json<\/em><span>&nbsp;<\/span>file. This frees up the<span>&nbsp;<\/span><em>Azuredeploy.parameters.json<\/em><span>&nbsp;<\/span>file for items that differ in each deployment i.e. the Address Space for the Virtual Network, different environment etc.<\/p>\n<h3 style=\"padding-bottom: 15px; margin-bottom: 30px; margin-top: 40px; border-bottom: 1px solid #f16020;\">End Note<\/h3>\n<p style=\"text-align: justify;\">It is easy to write a basic JSON template for Resource deployments. But it is a task fraught with danger if resources are not systematically named and deployed. Large scale deployments require careful planning.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why? Resource templates are a great concept, but are fraught with danger. Badly named resources and naming inconsistency across resources in different subscriptions can make it difficult to determine purpose. If a resource such as a Virtual Network or a Storage Account is badly named in a resource template file, you may find that you&hellip; <a class=\"more-link\" href=\"https:\/\/www.insentragroup.com\/au\/insights\/geek-speak\/cloud-and-modern-data-center\/automatically-naming-resources-in-an-azure-resource-management-template\/\">Continue reading <span class=\"screen-reader-text\">Automatically Naming Resources in an Azure Resource Management Template<\/span><\/a><\/p>\n","protected":false},"author":88,"featured_media":6570,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[21],"tags":[],"class_list":["post-1793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-and-modern-data-center","entry"],"_links":{"self":[{"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/posts\/1793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/comments?post=1793"}],"version-history":[{"count":2,"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/posts\/1793\/revisions"}],"predecessor-version":[{"id":20769,"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/posts\/1793\/revisions\/20769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/media\/6570"}],"wp:attachment":[{"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/media?parent=1793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/categories?post=1793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.insentragroup.com\/au\/wp-json\/wp\/v2\/tags?post=1793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}