Infrastructure as Code with Azure Bicep. - Yaser Adel Mehraban - E-Book

Infrastructure as Code with Azure Bicep. E-Book

Yaser Adel Mehraban

0,0
37,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

It’s no secret that developers don’t like using JSON files to declare their resources in Azure because of issues such as parameter duplication and not being able to use comments in templates. Azure Bicep helps resolve these issues, and this book will guide you, as a developer or DevOps engineer, to get the most out of the Bicep language.
The book takes you on a journey from understanding Azure Resource Manager (ARM) templates and what their drawbacks are to how you can use Bicep to overcome them. You will get familiar with tools such as Visual Studio Code, the Bicep extension, the Azure CLI, PowerShell, Azure DevOps, and GitHub for writing reusable, maintainable templates. After that, you’ll test the templates and deploy them to an Azure environment either from your own system or via a continuous integration and continuous delivery (CI/CD) pipeline. The book features a detailed overview of all the Bicep features, when to use what, and how to write great templates that fit well into your existing pipelines or in a new one. The chapters progress from easy to advanced topics and every effort has been put into making them easy to follow with examples, all of which are accessible via GitHub.
By the end of this book, you’ll have developed a solid understanding of Azure Bicep and will be able to create, test, and deploy your resources locally or in your CI/CD pipelines.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 181

Veröffentlichungsjahr: 2022

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Infrastructure as Code with Azure Bicep

Streamline Azure resource deployment by bypassing ARM complexities

Yaser Adel Mehraban

BIRMINGHAM—MUMBAI

Infrastructure as Code with Azure Bicep

Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rahul Nair

Publishing Product Manager: Niranjan Naikwadi

Senior Editor: Athikho Sapuni Rishana

Content Development Editor: Sayali Pingale

Technical Editor: Shruthi Shetty

Copy Editor: Safis Editing

Associate Project Manager: Neil Dmello

Proofreader: Safis Editing

Indexer: Sejal Dsilva

Production Designer: Sinhayna Bais

Marketing Co-Ordinator: Nimisha Dua

First published: December 2021

Production reference: 1151221

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80181-374-7

www.packt.com

To my wife, Rosa, for her sacrifices and for exemplifying the power of determination. To my mom, Sedigheh; there are no words that can express how I feel, and I thank you for what you made me. And to my two little angels, Ronika and Elika; please listen to what your mom says.

– Yas

Foreword

It's hard to overstate the benefits of defining your solution's Infrastructure as Code (IaC). Continuous delivery, continuous testing, quality control gates, automated security testing, and automated performance testing all benefit from having an automated approach to working with infrastructure.

Until recently, the gold standard of IaC on Azure has been ARM templates. It's fair to say that nobody particularly likes working with its arcane JSON syntax. As a result, it's been difficult for Azure customers to unlock all of the benefits of IaC. But with the introduction of Bicep, defining IaC for Azure hasn't just become easier – it's become fun.

In this book, Yas has taken his wealth of experience and combined a tutorial of the Bicep language with reference material covering its keywords and syntax. There is a lot of practical advice, too, with tips for using the Bicep tooling for Visual Studio Code and the Bicep linter. And to really get the best out of Bicep and IaC, look at the chapters about deployment pipelines and some recommended practices for writing good code.

I often say that Bicep has changed the game of Azure deployments. After you read this book, you'll have a solid foundation for planning your own automated deployment process for Azure.

– John Downs

Senior Customer Experience Engineer at Microsoft

It comes as no surprise that Yas has decided to put pen to paper and produce this book on IaC with Azure Bicep. As you read this, what will become evident is his passion for technology, innovation, and for helping people and organizations be their best. I have had the pleasure of working with Yas as his manager and seen his passion firsthand. He has an amazing way of breaking down the complex, evoking thought, discussion, encouraging ideas, and promoting self-belief. This stems from his upbringing and desire to achieve and bring out the best in himself and turn dreams into reality, with no better example of now achieving his goal of one day working for Microsoft.

I know you will enjoy the book as much as I have. You will be inspired by the level of detail and benefit from Yas's shared expertise.

– Edmondo Rosini

Director, Azure Technical Training at Microsoft

Contributors

About the author

Yaser Adel Mehraban is a self-taught and motivated software engineer and solution architect who lives in the most livable city in the world, Melbourne, Australia. He is currently working as an Azure technical trainer for Microsoft. Some might know him as the almond croissant addict cleverly disguised as a successful web developer.

He has over a decade of experience working in a variety of different teams and has helped them adapt DevOps and IaC to be able to increase team productivity when it comes to cloud resource deployment. Furthermore, he has a true passion for sharing knowledge, which has motivated him to give many international conference talks, write hundreds of technical blog posts, and publish courses on platforms such as Pluralsight.

When he is not working, he mostly spends his time with his family or on his woodworking projects, which vary depending on how much space is left in the house.

– I would like to thank Niranjan (project manager) who approached me at the start and has supported me throughout the entire writing process. In addition, I would like to thank Neil (project manager and editor) and Sayali (editor) for their dedication and support to help me write this book smoothly from start to finish. Also, thanks to the technical reviewers, Vaibhav and Alessandro, for their help in spotting my mistakes and validating the technical aspects, which adds so much to the book's practicality. And finally, thanks to my dear friends, John and Edmondo, who have expressed their support through their precious words about me and the book.

About the reviewer

Vaibhav Gujral is a thought leader and a seasoned cloud architect with over 15 years of extensive experience working with several global clients spanning multiple industries. In his current role, he is responsible for envisioning and creating enterprise cloud strategy and continually building and improving the cloud platform foundations that development teams build upon. Born and brought up in India, he has been based out of Omaha, NE, since 2016. Vaibhav holds a bachelor of engineering degree and is a Microsoft Azure MVP. He is also a Microsoft Certified Trainer and holds numerous Azure role-based certifications. He is a regular speaker at several user groups and conferences, and he also runs the Omaha Azure user group.

– I'd like to thank my wife, Geeta, and our two children, Saanvi and Rihaan, for their daily support and patience. I'd like to thank my parents, siblings, relatives, friends, and mentors for their guidance and continued support. Finally, I'd also like to thank Packt Publishing for the opportunity to review this book.

Table of Contents

Preface

Section 1: Getting Started with Azure Bicep

Chapter 1: An Introduction to Azure Bicep

Technical requirements

What is Azure Bicep?

IaC

ARM templates

Azure Bicep

Why was it created?

Why create a new revision?

What about current third-party tools?

How does it work?

Authoring experience

What happens to my ARM templates?

Bicep CLI

Summary

Chapter 2: Installing Azure Bicep

Technical requirements

Cross-platform installation

Installing the Azure CLI

Installing Bicep using the Azure CLI

Installing Bicep using Azure PowerShell

Installation on Windows

Installation using Windows Installer

Installation using Chocolatey

Installation using winget

Manual installation using PowerShell

Manual installation on macOS

Installing Bicep via Homebrew

Installing Bicep via Bash

Manual installation on Linux

Getting nightly builds

Working with Bicep in a Docker container

Working with an Azure CLI Docker container

Summary

Chapter 3: Authoring Experience

Technical requirements

Bicep extension for Visual Studio Code

Installing Visual Studio Code

Installing the Bicep extension

Snippets offered by the Bicep extension

Refactoring

Formatting

Using quick fixes

Configuring the Bicep linter

Customizing the linter

Using the Bicep CLI to use the linter

Bicep Playground

Compiling Bicep snippets

Decompiling an ARM template

Using sample templates in Bicep Playground

Summary

Chapter 4: Compiling and Decompiling Bicep Files

Technical requirements

Compiling Bicep files

Compiling a Bicep file using the Bicep CLI

Compiling and deploying a Bicep file using the Azure CLI

Compiling and deploying a Bicep file using Azure PowerShell

Troubleshooting possible errors and warnings

An invalid template

Linter errors

Decompiling ARM templates into Bicep

Using the Azure CLI

Using the Bicep CLI

Potential fixes after decompiling

Exporting templates and decompiling

Summary

Section 2: Azure Bicep Core Concepts

Chapter 5: Defining Resources

Technical requirements

Resource definition

Common properties

Resource-specific properties

Adding additional properties

Referencing existing resources

Referencing a resource that is in the same file

Referencing an already deployed resource

Explicit dependencies

Visualizing dependencies

Resource scopes

Resource group

Subscription

Management group

Tenant

Setting the scope at the resource level

Multi-scope Bicep files

Global functions

Bicep language specification

Structure

Whitespaces

Comments

Bicep type system

Supported data types

Simple types

Objects

Arrays

Union types

ARM and Bicep syntax comparison

Best practices for Bicep syntax

Summary

Chapter 6: Using Parameters, Variables, and Template Functions

Technical requirements

Parameters

Minimalistic definition

Setting default values

Using decorators

Using parameters within a Bicep template

Passing parameters during deployment

Variables

Defining variables

Using variables

Configuration variables

Template functions

The any function

Date functions

The bool function

Deployment functions

Numeric functions

Array functions

Object functions

Resource functions

String functions

Summary

Chapter 7: Understanding Expressions, Symbolic Names, Conditions, and Loops

Technical requirements

Understanding expressions

Unary operators

Comparison operators

Logical operators

Numeric operators

Accessor operators

Operator precedence and associativity

Exploring conditions

Deploy condition

New or existing resource

Runtime checks

Diving into resource iterations

Syntax

Loop index

Loop array

Loop array and index

Nested loops with conditions

Using batches

Summary

Chapter 8: Defining Modules and Utilizing Outputs

Technical requirements

Modules

Defining modules

Consuming a module

Additional considerations

Defining and configuring module scopes

Using Bicep outputs

Defining outputs

Conditional outputs

Returning multiple outputs with loops

Module outputs

Getting output values after deployment

Summary

Section 3: Deploying Azure Bicep Templates

Chapter 9: Deploying a Local Template

Technical requirements

Deploying Bicep with Azure PowerShell

Connecting to your Azure environment

Previewing changes with the what-if operation

Passing parameters

Deployment scopes

Deploying Bicep with the Azure CLI

Connecting to your Azure environment

Preview changes with what-if operation

Passing parameters

Deployment scopes

Troubleshooting possible errors and warnings

Compile-time errors and warnings

Deployment-time errors

Summary

Chapter 10: Deploying Bicep Using Azure DevOps

Technical requirements

Creating the Azure DevOps pipeline

Prerequisites

Creating a pipeline in Azure DevOps

Adding a validation step to our pipeline

Validating the deployment

Deploying the template

Adding the deployment step

Pushing the changes to your repository

Accessing the deployment output in the pipeline

Receiving outputs from a deployment

An alternative approach to accessing deployment outputs

Summary

Chapter 11: Deploying Bicep Templates Using GitHub Actions

Technical requirements

Creating a GitHub action

Prerequisites

Creating the workflow from code

Adding validation steps to the workflow

Adding an Azure CLI action to the workflow

Adding deployment steps to the workflow

Using the official Azure ARM action

Adding the Azure ARM action to the workflow

Accessing deployment outputs for later use

Accessing outputs from the Azure CLI action

Accessing outputs from the Azure ARM action

Summary

Chapter 12: Exploring Best Practices for Future Maintenance

Technical requirements

Applying version control and code flows for your IaC

Single pipeline approach

Separate pipelines for code and infrastructure

Source control everything

Idempotency and its importance

Idempotency

Immutability

Modularity and microservices

Bicep best practices

Parameters

Variables

Resource definitions

Outputs

Configuration set

Shared variable file

Managing service version updates

Azure Bicep's known limitations

Single-line objects and arrays

Newline sensitivity

No support for API profiles

CLI limitations

Summary

Other Books You May Enjoy

Section 1: Getting Started with Azure Bicep

In this section, as well as an introduction to Bicep and getting started, you will also learn how to create your first template, compile Bicep files, and convert ARM templates to Bicep.

This part of the book comprises the following chapters:

Chapter 1, An Introduction to Azure BicepChapter 2, Installing Azure BicepChapter 3, Authoring ExperienceChapter 4, Compiling and Decompiling Bicep Files

Chapter 1: An Introduction to Azure Bicep

In this chapter, you're going to learn what Azure Bicep is, and you'll get a quick bit of background on why it was created and what problems it is trying to solve. There will be a comparison with its predecessor, ARM templates, and at the end, you will learn about some of its limitations.

This chapter will give you insights into the reason why Microsoft went to all the trouble of creating Azure Bicep, even though there are already many different third-party tools out there with similar functionalities and feature sets. It is important to learn the reasoning to be able to learn the language without any bias and make practical use of its powerful features.

In this chapter, we are going to cover the following main topics:

What is Azure Bicep?Why was it created?How does it work?

Technical requirements

To make the most of this chapter, you will need to have a basic understanding of Infrastructure as Code (IaC), Azure ARM templates, and the Azure CLI. The code used throughout this chapter is stored in this GitHub repository: https://github.com/PacktPublishing/Infrastructure-as-Code-with-Azure-Bicep/tree/main/Chapter01.

What is Azure Bicep?

In this section, you will learn Azure Bicep and what it offers to developers and DevOps teams. There will be a few code snippets to get your eyes familiar with the syntax and, finally, an overview of its components and building blocks. But before we begin, let's review some concepts to make sure we are on the same page.

IaC

Currently, many companies try to automate their infrastructure creation and maintenance. To do that, and to further keep track of what is happening or has happened in their environments, they use a set of scripts or code files alongside tools and processes that streamline the whole deployment for them.

This practice is called IaC and helps every team to safely establish and configure the required infrastructure for their applications and solutions. This practice became even more simplified when all cloud providers added the ability for their customers to use it, which in terms of Microsoft is called Azure Resource Manager (ARM