Giter Club home page Giter Club logo

azure-dev-center-demos's Introduction

Azure DevBox and Azure Deployments demos for a Platform Engineering culture

Pre-requisites

In order to follow this tutorial, you need to have the following tools installed:

Install Azure Dev Center extension ๐Ÿงฉ

az extension add --name devcenter

Set variables

To make it easier to follow this tutorial, let's set some variables.

source scripts/00-minimal-setup/00-variables-and-registrations.sh

Minimal setup: resource group ๐Ÿ“ฆ, Dev Center ๐Ÿข and projects ๐Ÿ‘ท๐Ÿผโ€โ™€๏ธ๐Ÿ‘ท๐Ÿปโ€โ™‚๏ธ

Create a resource Group ๐Ÿ“ฆ

As every Azure resource, the first thing you need to do is to create a resource group. Also, in a enterprise environment, you will probably want to create a virtual network to connect your dev boxes to your corporate network.

source scripts/00-minimal-setup/01-create-rg.sh
Create a Dev Center ๐Ÿข

Now that you have a virtual network and also a custom image let's create a Dev Center. This is the place where you will manage your projects. You have to give the Dev Center permissions to the gallery

source scripts/00-minimal-setup/02-create-dev-center.sh
Create some projects ๐Ÿ‘ท๐Ÿผโ€โ™€๏ธ๐Ÿ‘ท๐Ÿปโ€โ™‚๏ธ

Projects in Dev Box should represent a team or a group of people that will use the same dev boxes. For example, you can create a project for your backend team, another for your frontend team, and so on.

source scripts/00-minimal-setup/03-create-projects.sh

Basic setup: Create a Dev Box with a image from the Azure Marketplace

Create a Dev Box Definition ๐Ÿ“ฆ

Dev Box definitions are created within a project and they carry information about the dev box and any requirements for using it to create VMs. This includes the image version, the size of the VM, and the virtual network to connect to.

source scripts/01-basic-devbox/01-create-dev-box-definition.sh

Create a Dev Box Pool

A dev box pool is a collection of dev boxes that are created from the same dev box definition. You can create a dev box pool for each team or group of people that will use the same dev boxes.

source scripts/01-basic-devbox/02-create-dev-box-pool.sh

Access to the Developer Portal

Congrats ๐ŸŽ‰, you have created a dev box pool. Now you can access the Developer Portal and create a new dev box.

The URL for the developer portal is https://devportal.microsoft.com

You can access with any user in the Devs group ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

Create a custom image

We have two options to create a custom image: using Azure Image Builder or using Packer.

Using Azure Image Builder

Azure Image Builder is a service that allows you to create custom images in Azure. You can use it to create a custom image from a managed image, a shared image gallery image, or a generalized VM. You can also use it to create a custom image from a Packer template.

Create a Gallery ๐Ÿ–ผ

The first thing we need is a gallery.

source scripts/02-custom-devbox/image-builder/01-create-azure-compute-gallery.sh

Create the image definition โœ

Image definitions are created within a gallery and they carry information about the image and any requirements for using it to create VMs. This includes whether the image is Windows or Linux, release notes, and minimum and maximum memory requirements. It's a definition of a type of image.

source scripts/02-custom-devbox/image-builder/02-create-image-definition.sh

Create image version ๐Ÿž๏ธ

An image version is what you use to create a VM when using a gallery. You can have multiple versions of an image as needed for your environment. Like a managed image, when you use an image version to create a VM, the image version is used to create new disks for the VM. Image versions can be used multiple times.

In order to create your custom image you can use Azure Image Builder and for that you need a identity. This identity needs some permissions but there is no built-in role. So let's create a custom role for the image builder too.

source scripts/02-custom-devbox/image-builder/03-create-azure-image-builder-identity-and-role.sh

Lastly you need to define the ingredients for your new image: what is the image base, if some customization is needed and how much time it has the builder to build it.

We are going to use this template: custom-images/win11-with-vscode.json which install Visual Studio Code in a Windows 11.

source scripts/02-custom-devbox/image-builder/04-create-an-image-template.sh

And now just wait... a little bit โŒš

Congrats ๐ŸŽ‰, you have created a custom image. Now you can use it to create a new dev box.

source scripts/02-custom-devbox/image-builder/05-create-dev-box-definition.sh

After that you can create a dev box pool

source scripts/02-custom-devbox/image-builder/06-create-dev-box-pool.sh

and access the Developer Portal to create a new dev box.

Developer Portal URL: https://devportal.microsoft.com

You should see a Windows 11 with VS Code installed.

Create image template with Packer

The other option to create a custom image is to use Packer. Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.

The first thing you need to do is to install Packer. Once you have Packer installed, you can create a Packer template. In this repo we have several examples of Packer templates. You can use the packer-for-image-generation folder to create a custom image with Packer.

But first we need to create a new gallery for these packages. In order to execute packer you need a service principal:

SUBSCRIPTION_ID=$(az account show --query id -o tsv)
az ad sp create-for-rbac --name hcp-packer --role Contributor --scopes /subscriptions/$SUBSCRIPTION_ID

IMPORTANT: Please replace the variables.pkr.hcl file with your own values.

With that in place, you can create this resources using the terrafom script in the terraform folder.

source scripts/02-custom-devbox/packer/01-create-resources-using-tf.sh

Once you have the custom images created, you need to attach the gallery to the Dev Center:

source scripts/02-custom-devbox/packer/02-assign-packer-gallery.sh

Create the Dev Box definitions:

source scripts/02-custom-devbox/packer/03-create-dev-box-definitions-for-packer-images.sh

And create the Dev Box Pools:

source scripts/02-custom-devbox/packer/04-create-dev-box-pool-with-packer-images.sh

Check the portal and create a new dev box with the new images.

https://devportal.microsoft.com

Configuration-as-code customization (preview)

You can use configuration-as-code to customize the dev box. Configuration-as-code allows you to define the configuration of a dev box in a YAML file. You can use configuration-as-code to customize the dev box by installing software, configuring settings, and running scripts.

But first platform admin teams must choose which tasks are available to their developers by defining a Catalog of tasks. A Catalog is a collection of tasks that developers can use to customize their dev boxes. Each task in the catalog is a YAML file that defines a task that can be run on a dev box plus a script that is executed when the task is run.

For this environment we are going to allow the tasks in the allowed-tasks folder. So we need to attach this folder to the Dev Center.

source scripts/02-custom-devbox/customizations/00-attach-catalog-with-allowed-tasks.sh

So now you can create a new dev box with some customizations. Just go to the Developer Portal and upload the devbox-customizations/workload.yaml file. After creation you should see all this installed:

  • Visual Studio Code

Integrate Dev Box with a virtual network

Create a network connections ๐Ÿ“ž

If you need to connect to a virtual network, you can create a network connection. A network connection is a connection between a dev box and a virtual network. You can create a network connection for each virtual network that you want to connect to a dev box. After you create a network connection, you have to attach it to a dev center.

source scripts/03-network-integration/01-create-vnet-and-network-connections.sh
Create a SQL Server virtual machine in the vnet
source scripts/03-network-integration/02-create-vm-with-sql-server-in-that-vnet.sh
Create a devbox definition with an image with Azure Data Studio in order to connect to the SQL Server
source scripts/03-network-integration/03-create-devbox-with-vnet-integration.sh
Create a dev box pool ๐Ÿ–ฅ๏ธ

Now that you have a dev box definition, you can create a dev box pool in your project. A dev box pool is a set of dev boxes that are created from the same dev box definition.

source scripts/03-network-integration/04-create-dev-box-pool.sh

Got to the developer portal and create a dev box ๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป

The URL for the developer portal is https://devportal.microsoft.com

Azure Deployments

An environment definition is composed of least two files:

  • An Azure Resource Manager template (ARM template) in JSON file format. For example, azuredeploy.json.
  • A configuration file that provides metadata about the template. This file should be named environment.yaml.

You can see some examples in the catalog folder.

source scripts/04-environments/01-create-a-catalog.sh

How to define environments

You can use BICEP and then convert it to ARM template.

az bicep build --file {bicep_file} --outfile {out_file}

for example:

az bicep build --file catalog/ARMTemplates/tour-of-heroes-environment/main.bicep --outfile catalog/ARMTemplates/tour-of-heroes-environment/azuredeploy.json

Or, in private preview, you can use Terraform.

Schedule an environment for deletion as a project admin: https://learn.microsoft.com/en-us/azure/deployment-environments/how-to-schedule-environment-deletion#schedule-an-environment-for-deletion-as-a-project-admin

Check the usage

source scripts/11-check-usage.sh

Clean up

Congratulations ๐ŸŽ‰ You did it! Now you can delete all and go to sleep ๐Ÿ›Œ๐Ÿ’ค

Please keep in mind that before you delete the resources, you need to delete the environments created by the users.

source scripts/clean-up.sh

azure-dev-center-demos's People

Contributors

0gis0 avatar

Stargazers

Julia Kordick avatar Rachid Zarouali avatar

Watchers

 avatar

azure-dev-center-demos's Issues

Unable to assign custom role by role name

The script that creates the azure image builder identity and role seems to have an error when running, where if assigning the role by custom role name errors out (can not find role definition - e.g. "Azure Image Builder Service Image Creation Role").

Link to code: https://github.com/raykao/azure-dev-box-demo/blob/76bcd0fad388087ab8ccbefa385eddb13b509a43/scripts/02-custom-devbox/image-builder/03-create-azure-image-builder-identity-and-role.sh#L44-L45

However if using the uuid of the created custom role, this command succeeds as expected.

Suggested fix:

  • use role uuid in the --role parameter flag in az role assignment create instead of the display name for role?

Ensure user has graph api permissions

On certain commands, the azure cli will leverage the Microsoft Graph API to check if an entity (app/user) exists in the Entra (Artist formerly known as Azure Active Directory/AAD) tenant.

As such a user/spn must have graph API permissions to do so via the cli. Otherwise there must be steps to manually add the entity with the required permission on the correct resource scope.

As an example:
https://github.com/0GiS0/azure-dev-box-demo/blob/76bcd0fad388087ab8ccbefa385eddb13b509a43/scripts/02-custom-devbox/image-builder/01-create-azure-compute-gallery.sh#L12

This line using the --assignee parameter would require Microsoft Graph API access to query for the assignee resource object and then assign the role. You will see/receive an error like this:

Failed to query xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx by invoking Graph API. If you don't have permission to query Graph API, please specify --assignee-object-id and --assignee-principal-type.

Workaround:

  • In a workshop scenario you can manually add the permission/role assignment on the resource group via the Azure Portal if a user receives Graph API permission error in the CLI.

Potential Fixes:

  • Add/enable Graph API permission for the user/spn
  • use the --assignee-object-id and --assignee-principal-type ServicePrincipal flags instead of --assignee only flag to bypass Msft Graph API calls

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.