Loading...

ARM Deployment Stacks now Public Preview!

ARM Deployment Stacks now Public Preview!

TL; DR – Deployment Stacks is a new resource type for managing a collection of Azure resources as a single unit for faster update and delete (cleanup), as well as more granular capabilities for preventing unwanted changes to resources. 

The Problem: managing the lifecycle (creates, updates, deletes) of resources across multiple Azure scopes (RG, MG, Sub) is both complex and time consuming. Ensuring critical resources have the proper guard rails in place also adds to the complexity of resource management.

  • Cleanup: resources with the same lifecycle are often created across multiple scopes, adding the complexity of many 1-to-1 operations for updating/deleting (e.g. deleting test Storage accounts or VMs across many RGs). 
  • Unwanted changes: many developers get contributor rights to certain scopes to work on their projects. Sometimes accidental changes can be done to resources (e.g. deleting a resources). 

Why Deployment Stacks?

As a native solution, Deployment Stacks will enable users to manage a collection of resources across scopes as a single atomic unit.

The Solution: 1st Party resource enabling 1-to-many CRUD operations and resource change prevention. 

  • Cleanup: easily delete or update resources across scopes with a single call to the deployment stack resource as a 1-to-many operation.
  • Unwanted changes: block changes to managed resources with deny settings capability of a deployment stack.

Deployment Stacks Docs Reference:

Before getting started, please install the prerequisites listed in our docs:

The Deployment Stack Resource

 A deployment stack is a resource that deploys a template file (ARM or Bicep) as a deployment object. Beyond the familiar capabilities of the deployments object, the resources a deployment stack creates are known as "managedResources" and can be easily updated/deleted with a single operation on the deployment stack. "managedResources" can be deleted directly via delete of a deployment stack or indirectly via updates to the template and "actionOnUnmanage" behavior of the deployment stack, specified via delete flags. Depending on the combination, a managed resource can become detached or deleted on the subsequent update to the deployment stack resource. To detach a resource is to disassociate it from a deployment stack and not delete it.   Unwanted changes to "managedResources" can be prevented with the deny settings mode capability, blocking writes and deletes with ability to exclude specific principals or actions.

Create and Update Deployment Stack Resource

A deployment stack can be created at different scopes, such as, Resource Group, Subscription, and Management Group scope. To create a deployment stack, we need the following:

  1. Create a main template (e.g. azuredeploy.json or main.bicep) that defines the "managedResources" to be created by the deployment stack.
  2. Decide on what Deny Setting (e.g. DenyDelete or DenyWriteAndDelete) to specify on creation of a deployment stack
  3. Decide on "actionOnUnmanage" behavior of "Detach" or "Delete". If no delete flag is specified, the default behavior is always "Detach". 

For example, here is a CLI command for creating a deployment stack at the subscription scope:

 

 

 

 

 

 

 

az stack sub create --name "storageStack-DevEnv" --template-file "testStorageAccounts.bicep" --location "westus" --deny-settings-mode "DenyDelete"

 

 

 

 

 

 

 

 

Note: Use 'az account set' to specify the subscription scope for this deployment stack. 

 

Required properties:

  • --name: name for the deployment stack resource - storageStack-DevEnv"
  • --template-file: main template to be deployed by the stack - "testStorageAccounts.bicep"
  • --location: region of deployment for the subscription scope stack - "westus"
  • --deny-settings-mode: setting for the deny assignment created by the stack - "DenyDelete"

In this example, the deployment stack created named "vmStack-DevEnv" is created at the subscription scope with deny setting of "DenyDelete" and actionOnUnmanage of "Detach". We can verify this by viewing the deployment stack resource with the following command:

 

 

 

 

 

 

 

az stack sub show --name "storageStack-DevEnv"

 

 

 

 

 

 

 

The result will contain all information on the specified deployment stacks object, such as, resource ID of the deployment stack, array of managed resources, deny setting configurations, and more, including the "actionOnUnmanage" behavior:

 

 

 

 

 

 

 

"actionOnUnmanage": { "managementGroups": "detach", "resourceGroups": "detach", "resources": "detach" }

 

 

 

 

 

 

 

 

For this example, resources removed from the "testStorageAccounts.bicep" file will be removed from "managedResources" and continue to exist in Azure, on the next update to the deployment stack. If you decide that instead you want the resources removed from the template to be deleted from Azure, you can change the "actionOnUnmanage" behavior by sepcifying the proper delete flag:

  • --delete-resources: will delete resources and detach resource groups
  • --delete-all: will delete both resources and resource groups

 

 

 

 

 

 

az stack sub create --name "storageStack-DevEnv" --template-file "testStorageAccounts.bicep" --location "westus" --deny-settings-mode "DenyDelete" --delete-resources

 

 

 

 

 

 

 

Given the stack was updated with the flag "--delete-resources", the resulting state of "actionOnUnmanage" will be the following:

 

 

 

 

 

 

 

"actionOnUnmanage": { "managementGroups": "detach", "resourceGroups": "detach", "resources": "delete" },

 

 

 

 

 

 

 

You can also view the deployment stack resource in the Azure portal by navigating to the scope at which it was created, and finding the Stacks options within Settings:

 
 

deployment-stack-portal-group-list-stacks.png

 

Beyond deciding on the behavior for "actionOnUnmanage" it is also important to define what deny setting mode should the deployment stack use. Today a deployment stack resource can have "--deny-settings-mode": 

  • None
  • DenyDelete: blocks managedResources from being deleted
  • DenyWriteAndDelete: blocks write and delete attempts to managedResources

In our initial example, we specified DenyDelete for our deny setting. Behind the scenes, a deployment stack resources creates a deny assignment for the managedResources. Meaning that users that got the test storage accounts provisioned can make updates/writes to those accounts but not delete them. In some cases, you might need some flexibility or stop gap measure for the deny assignment. For example, you may want to exclude a particular user from the deny assignment, such that they can go and delete the resource manually (outside of the context of a deployment stack), or maybe you want to exclude a particular action for all users. These options are available in the form of:

  • "--deny-settings-excluded-principals": excludes listed AAD principal IDs from the deny assignment 
  • "--deny-settings-excluded-actions": excludes listed RBAC actions from the deny assignment

Here is an example of what a command to create a deployment stack would look like with these flags set:

 

 

 

 

az stack sub create --name "storageStack-DevEnv" --template-file "testStorageAccounts.bicep" --deny-settings-mode "DenyDelete" --deny-settings-excluded-principals "12304812408-2148124081" --deny-settings-excluded-actions "Microsoft.Storage/storageAccounts/delete" --delete-resources --location "westus"

 

 

For more information on deployment stacks, please visit our docs and our GitHub. 

 

References

Published on:

Learn more
Azure Governance and Management Blog articles
Azure Governance and Management Blog articles

Azure Governance and Management Blog articles

Share post:

Related posts

Azure Landing Zones - Policy Refresh Q1 FY25

ALZ - Policy Refresh Q1 FY25 is here! As you may be aware, the ALZ team release cadence is now on quarterly basis to help customers and partne...

1 year ago

Custom Policy- Reusable Logs Templates

Reusable Templates for Sending Logs to Log Analytics Workspace   Challenge:   When it comes to developing custom policies for sendin...

1 year ago

Enhancements to Azure Monitor Baseline Alerts for Azure Landing Zones

Introduction   Welcome to our latest blog post where we dive into a number of exciting new key updates, highlight the new portal accelera...

1 year ago

Introducing the Azure Policy Community Repo

Introducing the Azure Policy Community Repo   What is the Azure Policy Community Repo? The Azure Policy Community Repo is a collaborativ...

2 years ago

General Availability: Vaulted backups for Azure Blob Storage

We are excited to announce the general availability of vaulted backups for Azure Blob Storage. Vaulted backups can help you achieve complete p...

2 years ago

Azure Update Manager to support CIS hardened images among other images

What’s coming in by end of July 2024: Azure Update Manager will add support for 35 CIS hardened images. This is the first time that Update Man...

2 years ago

Mastering your cloud journey: Essentials to Innovating, Migrating and Modernizing, on Azure

We are living during a time of rapid growth in AI technologies and seeing cloud complexity increase as a result of those advanced workloads, w...

2 years ago

Public Preview Announcement: Azure Policy Built-in Versioning

Welcome to a new era of policy management, where policy definitions are more agile, adaptable, and accessible than ever before! We are thrille...

2 years ago

Announcing Azure Monitoring Agent support in Azure Landing Zones

Introduction   Hello and welcome to another blog post about Azure Landing Zones, the best practice framework for accelerating your cloud...

2 years ago

Announcing the General Availability of Change Actor

Change Analysis  Identifying who made a change to your Azure resources and how the change was made just became easier! With Change Analys...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.