Giter VIP home page Giter VIP logo

azure-sample-arm-template-architecture's Introduction

Azure-Sample-ARM-Template-Architecture

Shows how to build a set of linked templates with conditions, loops, array and complex parameters. The templates have been developed as a set of nested templates that allows for team collaboration on the templates (having one large template get very hard to manage). You can author and test each linked (nested) template individually and then after successfully testing, incorporate the template into the master template. This template allows for the parameters files to the updated to add new VMs, subnets and nsgs.

How to run

  • Download azuredeploy.parameters.json
  • Make your edits
  • Click the Deploy to Azure button
  • Click "Edit Parameters" and upload your azuredeploy.parameters.json

Running from a GiHub Repo

If you will be keeping these scripts in your GitHub repo you can still used linked ARM templates. Azure needs to reach out to a public URL to download/include a linked template. If your GitHub is not public (and most enterprises are not), then you need a proxy to call which will securely download your template. I wrote a proxy which is an Azure function to perform such a task. The Function will login to your GitHub and transmit the ARM template securely to Azure.

https://github.com/AdamPaternostro/GitHub-Azure-Function-Proxy-for-ARM-Template

NOTE: If you are using Azure DevOps or another source control, you just need to emulate the Azure Function code for your source control repository of choice.

Actions

Overview of Templates

The below diagram shows the layout of the templates. The templates have been nested such that each nested template can be tested independently and then linked in the master template. The master template will pass the parameters to each linked template and reference an dependencies between the linked templates.

alt tag

Specific template notes

  • The VM template has the most complex set of parameters
    • The availabilitySet parameter can be set to an empty string will specifics no availibility set for the VM.
    • The publicIPAddress parameter can be set to true or false which determines if the NIC card is assigned a public IP address. Conditions are used in the ARM template to achive this.
    • The VM template uses just a single parameter file which is shared between the NIC, Public IPs and the VMs. This simplified some testing.
  • The VNET template does a loop to create each subnet. The subnets cannot be placed in a seperate linked template since when you run the ARM template a second time it will fail. The VNET will attempt to remove all the subnets when the subnets are in a seperate template.

Examples

  • azuredeploy.availabilityset uses the copy command to create many exact copies
  • azuredeploy.vm-nic uses an "if" statement to conditionally create a sub-resource (or null out the JSON)
  • azuredeploy.vnet uses a copy command for a sub-resource

To Run via command line (Linux)

# Login
az login

# Select Subscription
az account set -s REPLACE_ME

# Script parameters
resourceGroup="Azure-Sample-ARM-Template-Architecture"
location="eastus"
today=`date +%Y-%m-%d-%H-%M-%S`
deploymentName="MyDeployment-$today"

# Create resource group
az group create \
  --name        $resourceGroup \
  --location    $location

# Deploy the ARM template
az group deployment create \
  --name                 $deploymentName \
  --resource-group       $resourceGroup \
  --template-file        azuredeploy.json \
  --parameters           @azuredeploy.parameters.json \
  --mode                 Incremental

# Clean up resource group
az group delete --name $resourceGroup

To Run via command line (Powersehll)

# Login
Connect-AzAccount

# Select Subscription
$subscriptionId="REPLACE_ME"
$context = Get-AzSubscription -SubscriptionId $subscriptionId
Set-AzContext $context

# Script parameters
$resourceGroup="Azure-Sample-ARM-Template-Architecture"
$location="eastus"
$today=(Get-Date).ToString('yyyy-MM-dd-HH-mm-ss')
$deploymentName="MyDeployment-$today"

# Create resource group
New-AzResourceGroup -Name $resourceGroup -Location $location

# Deploy the ARM template
New-AzResourceGroupDeployment -Name $deploymentName -ResourceGroupName $resourceGroup -TemplateFile azuredeploy.json -TemplateParameterFile azuredeploy.parameters.json -Mode Incremental

# Clean up resource group
Remove-AzResourceGroup -Name $resourceGroup 

References

azure-sample-arm-template-architecture's People

Contributors

adampaternostro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.