Azure Resource Manager (ARM) templates are declarations of Azure resources in the JSON format to provision and maintain them using infrastructure as code. This book gives practical solutions and examples for provisioning and managing various Azure services using ARM templates.
The book starts with an understanding of infrastructure as code, a refresher on JSON, and then moves on to explain the fundamental concepts of ARM templates. Important concepts like iteration, conditional evaluation, security, usage of expressions, and functions will be covered in detail.
You will use linked and nested templates to create modular ARM templates. You will see how to create multiple instances of the same resources, how to nest and link templates, and how to establish dependencies between them.
You will also learn about implementing design patterns, secure template design, the unit testing of ARM templates, and adopting best practices.
By the end of this book, you will understand the entire life cycle of ARM templates and their testing, and be able to author them for complex deployments.
Author(s): Ritesh Modi
Publisher: Packt Publishing
Year: 2019
Language: English
Pages: 234
Cover
Title Page
Copyright and Credits
About Packt
Foreword
Contributors
Table of Contents
Preface
Section 1: ARM Template Foundational Skills
Chapter 1: Infrastructure as Code and Configuration Management
What is configuration management?
Infrastructure as Code
What are ARM templates?
Designing ARM templates
A brief primer on JSON
Azure Resource Manager
Provisioning
Parallel
Multi-region
API-driven
Automation
Management
Tags
Resource groups
Hierarchical
Monitoring
Logs
Alerts
Actions
Governance
Role-based access control
Policies
Locks
Summary
Chapter 2: Azure Resource Manager Templates
Setting up the development environment
Using Visual Studio 2017 as a development environment
Using Visual Studio Code as a development environment
ARM template structure
Writing your first template
Template deployment
Deployment using Azure portal
Deployment using the Azure CLI
Deployment using PowerShell
Understanding Complete and Incremental deployment
How does Incremental take care of these differences?
How to create and apply configuration in the case of Complete deployments
Parameters
Structure of a parameter in an ARM template
Referencing a parameter within a template
Grouping parameters
Variables
Accessing variables
Summary
Chapter 3: Understanding Core Elements of ARM Templates
ARM template expressions
ARM template functions
Resources
Resource names
Resource types
API Version
Resource properties
Resource locations
Resources and nested resources
Outputs
A complete template
Nesting resources
Understanding dependsOn
Using references
Understanding resourceId
Using linked templates
Nested templates
Summary
Chapter 4: Advance Template Features
Creating multiple instances of a resource type
Creating multiple instances of a resource type, using Serial mode
Creating multiple instances of a resource property
Using copy to generate multiple variables
Conditions in ARM templates
Conditions that return a Boolean value
Conditions that return condition values
Advanced deployments
Using copy with deployment resources
Creating resource groups, using ARM templates
Deploying resources into multiple resource groups, using the deployment resource
Deploying resources into multiple resource groups in multiple subscriptions
Creating Nested Deployments
Summary
Section 2: ARM Template Advanced Concepts
Chapter 5: IaaS Solutions Using Templates
Configuration inside an Azure virtual machine
Protecting scripts using SAS tokens
Using protectedSettings
CustomScriptExtension as separate resource
Getting output from CustomScriptExtension
Using CustomScriptExtension with Linux virtual machines
Desired State Configuration
Using configuration data
Summary
Chapter 6: Unit Testing ARM Templates
Unit testing
Unit testing ARM templates
Retrieving outputs from ARM templates
Using Pester
Setting up the test harness
Unit testing of a storage account
Unit testing a public IP address
Unit testing virtual networks
Unit testing an NIC
Unit testing a virtual machine
The complete unit test script
Summary
Chapter 7: Design Patterns
Why use modular ARM templates?
Single responsibility principle
Known configuration/T-shirt sizing
Scenario
Technical prerequisites
Setting up Azure login and subscription
New resource group
Creating an Azure Storage Account
Creating an Azure Storage blob container
Generating an Azure Storage SAS token
Uploading ARM templates to storage
Creating an Azure Key Vault
Creating secrets in Key Vault
Creating the Azure AD Service Principal
Assigning permissions to a Service Principal on Key Vault
Deploying the solution
Log to Azure using Service Principal
Deploying the ARM template
Template patterns
Modular ARM templates
Generalized templates
Azure SQL template
App service plan template
Azure App Services template
Using Key Vault for passwords and secrets
Static usage of Key Vault information
Dynamic declaration of Key Vault information
Dependencies between resources
Creating multiple resources in loop
Tagging of resources
Runtime sharing of property values
Redefining resources in the same template
Summary
Chapter 8: ARM Template Best Practices
Use resourceId function
Generate Resource Identifier used multiple times
Use Comments
Use Tags for resources and resource groups
Use parameters sparingly
Group related parameters
Order parameters alphabetically
Constraint parameters if possible
Parameter's defaultValue and API versions
Declare All Resources as top-level resources
Output Resource Properties and Configuration
Resource-naming conventions
Storage of Linked templates
Resource Dependencies
Using Key Vaults for secrets
Using ContentVersion
Deployment – Best Practices
Summary
Other Books You May Enjoy
Index