<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pedro Maia Costa</title>
    <description>The latest articles on DEV Community by Pedro Maia Costa (@pnmcosta).</description>
    <link>https://dev.to/pnmcosta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F36988%2F0a79733f-93e1-4c97-a042-274e123db6df.png</url>
      <title>DEV Community: Pedro Maia Costa</title>
      <link>https://dev.to/pnmcosta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pnmcosta"/>
    <language>en</language>
    <item>
      <title>Quick Tips for Advanced Azure Resource Manager Templates deployment with Visual Studio 2017</title>
      <dc:creator>Pedro Maia Costa</dc:creator>
      <pubDate>Thu, 22 Feb 2018 00:15:05 +0000</pubDate>
      <link>https://dev.to/pnmcosta/quick-tips-for-azure-resource-manager-templates-authoring-in-visual-studio-2017--1dbm</link>
      <guid>https://dev.to/pnmcosta/quick-tips-for-azure-resource-manager-templates-authoring-in-visual-studio-2017--1dbm</guid>
      <description>&lt;p&gt;With Visual Studio (install Azure SDK with it) you can now create a &lt;code&gt;Azure Resource Group&lt;/code&gt; project to manage your resources in multiple Azure Subscriptions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/010n6.jpg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wyQKgS80--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.stack.imgur.com/010n6.jpg" alt="create"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are some excellent guides online about how Visual Studio works with the Json templates, I got started with this &lt;a href="https://www.youtube.com/watch?v=Rl8PJ4lH1So"&gt;video&lt;/a&gt; by Eliot Mansfield and the source code &lt;a href="https://github.com/eliot-trustm/FirstARMproject"&gt;on GitHub&lt;/a&gt; because I wanted to make sure I started in a modular approach for my own resources and any that clients may require.&lt;/p&gt;

&lt;p&gt;I'm half way building my project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/PanZH.jpg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1wQgFlVC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.stack.imgur.com/PanZH.jpg" alt="project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But I can already deploy &lt;code&gt;key-vaults&lt;/code&gt;, &lt;code&gt;storage accounts&lt;/code&gt;, &lt;code&gt;virtual networks&lt;/code&gt;, &lt;code&gt;vnet gateways&lt;/code&gt;, &lt;code&gt;virtual machines&lt;/code&gt;, etc all organised, parameterized and maintained within my resource groups, all in a few clicks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/eovJT.jpg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vums4kes--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.stack.imgur.com/eovJT.jpg" alt="deploy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If anyone would like to embark in such a project here are some tips that may save you some time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make sure templates are modular, naming resources appropriately is a must, I've taken Eliot's approach and prefix everything with the resource type, remember resources are not deleted when redeploying templates, you can keep your infrastructure up to date by modifying the templates and rerunning in most cases (I think, haven't tested all scenarios, but hope so!)&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates"&gt;linked templates&lt;/a&gt; whenever possible, but remember these need to be published to an online location. If you're not storing the templates publicly, use a storage account from Azure.&lt;/li&gt;
&lt;li&gt;If you use the &lt;code&gt;_artifactsLocation&lt;/code&gt; and &lt;code&gt;_artifactsLocationSasToken&lt;/code&gt; parameters in the template, when deploying via Visual Studio it will ask for a &lt;code&gt;Artifact storage account&lt;/code&gt; where the &lt;code&gt;Deploy-AzureResourceGroup.ps1&lt;/code&gt; will upload all your templates and any files set as Content in the project's file properties (F4 when file selected in Solution Explorer) and replace the parameter values. But never include these parameters values manually in a parameters file as the deploy script will fail when trying to replace those with the generated values.&lt;/li&gt;
&lt;li&gt;I have not tested a linked template also linking to another template, seems untidy to me having to pass along the generated artifacts storage keys to the linked template, so I've been avoiding that.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Build the template links in variables, below is an example from one of my templates that uses the deploy scripts generated storage account location and SasToken parameters to access the container, &lt;a href="https://docs.microsoft.com/en-us/azure/storage/common/storage-dotnet-shared-access-signature-part-1#how-a-shared-access-signature-works"&gt;click here&lt;/a&gt; to find out more about the SasToken.&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "variables": {
        "templates": {
          "vm": {
            "folder": "nestedtemplates",
            "fileName": "vm.json"
          },
          "deploy": {
            "folder": "rg-lab-superadmin",
            "fileName": "deploy.sh"
          }
        },
        "templateLinks": {
          "vm": "[concat(parameters('_artifactsLocation'), '/', variables('templates').vm.folder, '/', variables('templates').vm.fileName, parameters('_artifactsLocationSasToken'))]",
          "deploy": "[concat(parameters('_artifactsLocation'),  '/', variables('templates').deploy.folder, '/', variables('templates').deploy.fileName, parameters('_artifactsLocationSasToken'))]"
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can use the same principal of the artifacts location above for scripts you want to execute on a targeted VM with the &lt;a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/extensions-customscript"&gt;custom script extension&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom scripts on VM's should be redeployable to the same VM over and over again, as you may need to redeploy a whole resource group that includes the VM and those scripts need to consider that.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;VNet resources must be in the same location but not necessarily the same resource group, you can plan for this within the templates, for example whenever I need a vnet resource I also ask for the resource group it's in so you can create the appropriate &lt;a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-resource#resourceid"&gt;resourceId()&lt;/a&gt; on your template. A common scenario is when you create a VM, my template also created the NIC and this needs to be referenced properly to the vnet that may be on another resource group.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is not possible yet to create container in Storage Accounts directly with an ARM template, however a work round is to include a VM on your template and run a &lt;a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/extensions-customscript"&gt;custom script&lt;/a&gt; on it that would create the container on the storage account using the CLI, Powershell or other Azure management options.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Thanks to &lt;a href="https://stackoverflow.com/users/6067741/4c74356b41"&gt;@4c74356b41&lt;/a&gt; on SO, I got taught that you can call object properties dynamically by name &lt;code&gt;"[reference(x)[parameter(y)]]"&lt;/code&gt; in nested &lt;code&gt;[]&lt;/code&gt; if you ever require to do so.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will try and keep this post updated as I keep developing the infrastructure for my requirements.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>devops</category>
      <category>visualstudio</category>
    </item>
  </channel>
</rss>
