{"id":380,"date":"2019-09-17T18:51:33","date_gmt":"2019-09-18T00:51:33","guid":{"rendered":"http:\/\/draith.com\/?p=380"},"modified":"2019-09-17T18:51:33","modified_gmt":"2019-09-18T00:51:33","slug":"azure-arm-fragments","status":"publish","type":"post","link":"https:\/\/draith.com\/?p=380","title":{"rendered":"Azure ARM Fragments"},"content":{"rendered":"\n\n\n<h2 class=\"wp-block-heading\">SCOM Trick adopted for Azure ARM<\/h2>\n\n\n\n<p>I am working on a project for a very popular conference &#8211; working on backend automation that controls everything from speaker coordination to session scheduling.\u00a0 The current task at hand involves deploying the entire suite of Logic Apps, Azure Automation accounts, Azure Functions, etc&#8230;\u00a0 These would all be deployed to a new Resource Group.\u00a0 When deploying these resources for a new conference a few things change &#8211; changing the conference name from &#8216;Jazz&#8217; to &#8216;Midway&#8217; for example, or changing the backend data sources.\u00a0\u00a0<\/p>\n<p>Normally you would use Azure ARM Template Parameters to pass these values when you deploy the resources, and you would be absolutely right!\u00a0 They are powerful assets to have in your pocket.\u00a0 It does get a bit dodgy, however, when you start to deploy Logic Apps in the ARM template and those Logic Apps have parameters of their own.\u00a0\u00a0<\/p>\n<p>Logic Apps have parameters and variables all their own, and they are defined just like parameters and variables in ARM templates.\u00a0 When you want to deploy a Logic App that has parameters you can put them in the ARM Template and reference them in the Logic App, or you can use an ARM template expression in the Logic App.\u00a0 <a href=\"https:\/\/platform.deloitte.com.au\/articles\/preparing-azure-logic-apps-for-cicd\">The latter is not a popular idea<\/a>, and the former doesn&#8217;t evaluate the parameters until the execution of the Logic App.\u00a0 That obviously makes it difficult to work on the Logic App after it&#8217;s deployed.<\/p>\n<p>That&#8217;s when I got the idea of using a popular SCOM tool &#8211; <a href=\"https:\/\/blogs.technet.microsoft.com\/kevinholman\/2016\/06\/04\/authoring-management-packs-the-fast-and-easy-way-using-visual-studio\/\">SCOM Fragments by Kevin Holman<\/a> &#8211; in order to get the best of both worlds.\u00a0 I wanted a quick way to deploy, and a quick way to edit after deployment.\u00a0 Cake and all that&#8230;.<\/p>\n<p>The idea is simplistic &#8211; Find\/Replace what you want to change before you deploy.\u00a0 Sounds simple, and it is!\u00a0 That is essentially how the SCOM Fragments work, and the same idea can be utilized here.\u00a0 Say, for example, you have a simple Conference Name parameter you want to change.\u00a0 The first thing you would do is build your Logic App like normal, keeping in place a static conference name.\u00a0 Export that template.\u00a0 Now, at the top of the template, add a new parameter to the parameters section in the template, like this:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code>{\n    \"$schema\": \"https:\/\/schema.management.azure.com\/schemas\/2015-01-01\/deploymentTemplate.json#\",\n    \"contentVersion\": \"1.0.0.0\",\n    \"parameters\": {\n        \"Conference_Name\": {\n            \"metadata\": {\n                \"defaultValue\": \"###Awesome_Conference_Name###\",\n                \"description\": \"Name of the conference - i.e. Management Conference 2019\"\n            }\n        },<\/code><\/pre>\n\n\n\n<p>Now, find your static conference name down in the code for the Logic App itself, and replace the name with ###Awesome_Conference_Name###.\u00a0 \u00a0That&#8217;s it!\u00a0 That is all that is needed to prepare your template for a rapid deployment.\u00a0 When you need to deploy this template, simply Find\/Replace ###Awesome_Conference_Name### with whatever text you want &#8211; i.e. &#8220;My Super Conference 2019&#8221;.\u00a0 It will update it both in the parameters section, and in the code itself.\u00a0 Do we really need the Parameter at the top of ARM template, especially if we are just going to replace the text ourselves before we deploy?\u00a0 That answer is no, but it does help immensely when keeping track when you have a ton of parameters:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code>{\n    \"$schema\": \"https:\/\/schema.management.azure.com\/schemas\/2015-01-01\/deploymentTemplate.json#\",\n    \"contentVersion\": \"1.0.0.0\",\n    \"parameters\": {\n        \"Conference_Name\": {\n            \"metadata\": {\n                \"defaultValue\": \"###Awesome_Conference_Name###\",\n                \"description\": \"Name of the conference - i.e. Management Conference 2019\"\n            }\n        },\n        \"Sharepoint_Base_URL\": {\n            \"defaultValue\": \"https:\/\/www.sharepoint.com\/sites\/Communications\"\n        },\n        \"Sharepoint_Speaker_ListName\": {\"defaultValue\": \"###Sharepoint_Speaker_ListName###\"},\n        \"Sharepoint_Session_ListName\": {\"defaultValue\": \"###Sharepoint_Session_ListName###\"},\n        \"Sharepoint_Session_Selection_Team_ListName\": {\"defaultValue\": \"###Sharepoint_Session_Selection_Team_ListName###\"},\n        \"Sharepoint_Approved_Sessions_ListName\": {\"defaultValue\": \"###Sharepoint_Approved_Sessions_ListName###\"},\n        \"Speaker_Agreement_URL\": {\"defaultValue\": \"###Speaker_Agreement_URL###\"},\n        \"Session_Submission_FormName\": {\"defaultValue\": \"###Session_Submission_FormName###\"},\n        \"Sched_Speakers_API\": {\"defaultValue\": \"###Sched_Speakers_API###\"},\n        \"Sched_Sessions_API\": {\"defaultValue\": \"###Sched_Sessions_API###\"},\n        \"Sched_Base_URL\": {\"defaultValue\": \"###Sched_Base_URL###\"},\n        \"Sched_API_Key\": {\"defaultValue\": \"###Sched_API_Key###\"},\n        \"MediaPack_URL\": {\"defaultValue\": \"###MediaPack_URL###\"},<\/code><\/pre>\n\n\n\n<p>By putting the parameters in your code, even though you aren&#8217;t going to use them in the way they are intended, you can easily see which ones you need to replace in one place.\u00a0\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SCOM Trick adopted for Azure ARM<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2,4,5,13],"class_list":["post-380","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-arm","tag-azure","tag-azure-automation","tag-logic-apps"],"_links":{"self":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380"}],"version-history":[{"count":0,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/380\/revisions"}],"wp:attachment":[{"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}