Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

Bicep - Deploying an Azure Elastic SAN

·889 words·5 mins· 100 views · 5 likes ·
Azure CLI Microsoft Microsoft Azure Bicep

Happy New Year, everyone! Kicking off our first article of the year, we’ll explore deploying Azure Elastic SAN using Bicep. Currently, there is no official Bicep module specifically for Elastic SAN implementation. However, by converting an ARM template, it is possible to create one to deploy Elastic SAN with Bicep. This approach is particularly useful for those looking to integrate Elastic SAN deployment now into their existing Bicep-based infrastructure setup and I must confess I’ve found it fun trying to do it.

Let’s get started and see how this deployment can be done.

Prerequisites>

Prerequisites #

Before you start, you’ll need the following to deploy and manage resources with Bicep:

  • You need Azure CLI version 2.20.0 or later to deploy Bicep files on your local machine.
  • A text editor or IDE of your choice (Visual Studio Code with Bicep extension is my recommendation)
Create the Bicep files>

Create the Bicep files #

The first step in deploying a Bicep template is to create the Bicep file that defines your resources. Create a new file named aes.bicep. This file will contain the code needed to define and configure the deployment of your resources.

@description('Basic configuration for the Elastic SAN resource.')
param elasticSan object = {
  name: ''
  location: ''
  baseSizeTiB: 0
  extendedCapacitySizeTiB: 0
  skuName: ''
  volumeGroupName: ''
  volumes: []
  subnetIds: []
}

@description('The tags to be associated with the resources.')
param tags object = {
  bicep: 'true'
  environment: 'jorgebernhardt.com'
}

resource elasticSanResource 'Microsoft.ElasticSan/elasticSans@2023-01-01' = {
  name: elasticSan.name
  location: elasticSan.location
  properties: {
    baseSizeTiB: elasticSan.baseSizeTiB
    extendedCapacitySizeTiB: elasticSan.extendedCapacitySizeTiB
    sku: {
      name: elasticSan.skuName
    }
  }
  tags: tags

  resource volumeGroup 'volumeGroups@2023-01-01' = {
    name: elasticSan.volumeGroupName
    properties: {
      protocolType: 'Iscsi'
      networkAcls: {
        virtualNetworkRules: [for subnetId in elasticSan.subnetIds: {
          id: subnetId
        }]
      }
    }

    resource volumes 'volumes@2023-01-01' = [for volume in elasticSan.volumes: {
      name: volume.name
      properties: {
        sizeGiB: volume.sizeGiB
      }
    }]
  }
}

output primaryResourceId string = elasticSanResource.id

elasticSan: This block defines the basic configuration for the Azure Elastic SAN resource, specifying parameters like the name, location, base and extended capacity sizes, SKU name, volume group name, volumes, and subnet IDs.

elasticSanResource: Creates an Azure Elastic SAN resource with properties such as name, location, base size, extended capacity, and SKU, also applying the defined tags.

volumeGroup: A nested resource within Elastic SAN, specifying the volume group name and properties including protocol type and network ACLs.

volumes: A nested resource within the volume group, defining each volume’s name and size in GiB.

Deployment scope>

Deployment scope #

You can target your deployment to a resource group, subscription, management group, or tenant. In this case, when creating Azure Elastic SAN, a resource group is needed to put all the necessary resources here. By default, when deploying a Bicep template, the scope where the resource should be deployed is a resource group.

You can use an existing Resource Group, or you can create a new Resource Group. If you want to know how to create a Resource Group using Azure CLI, check out this link.

Deploy the Bicep template using the Azure CLI>

Deploy the Bicep template using the Azure CLI #

Once your Bicep template is prepared, and you’ve selected your desired scope, you can proceed to deploy the template through the Azure CLI. To do so, execute the following commands.

Parameters>

Parameters #

Personalization is key to making your template reusable. With the parameters, you can easily tailor the template to your specific needs. You can use either inline parameters or a parameter file to pass parameter values. In my case, I will use a file to pass the parameters; here is an example.

{
  "elasticSan": {
    "name": "aes-demo-ne-01",
    "location": "northeurope",
    "baseSizeTiB": 2,
    "extendedCapacitySizeTiB": 1,
    "skuName": "Premium_LRS",
    "volumeGroupName": "vg01",
    "volumes": [
      {
        "name": "volume1",
        "sizeGiB": 1024
      },
      {
        "name": "volume2",
        "sizeGiB": 500
      }
    ],
    "subnetIds": [
      "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName}"
    ]
  },
  "tags": {
    "bicep": "true",
    "environment": "jorgebernhatdt.com"
  }
}

Important: Please note that the parameter file stores parameter values in plain text format. If you need to include a parameter with sensitive data, it’s recommended to store the value in a secure key vault.

Preview changes>

Preview changes #

Before deploying a Bicep file, you can preview the changes that will occur to your resources. Using what-if operations does not change existing resources; it simply shows you an output that includes color-coded results that allow you to see different changes.

az deployment group what-if \
--resource-group <resource-group-name> \
--template-file <filename>.bicep \
--parameters @<filename>.parameters.json
Deploy the Azure resource>

Deploy the Azure resource #

Finally, to deploy the template, run the following command.

az deployment group create \
--resource-group <resource-group-name> \
--template-file <filename>.bicep \
--parameters @<filename>.parameters.json
Validate the deployment>

Validate the deployment #

To check if your Elastic SAN resource is set up correctly, you can use Azure Portal or Azure CLI. For Azure CLI, run this command to list resources in a specific group and filter for Elastic SAN:

az resource list \
--resource-group <resource-group-name> \
--query "[?type=='Microsoft.ElasticSan/elasticSans']"

Alternatively, use the Azure CLI elastic-san extension for more detailed commands:

To view a specific Elastic SAN, use:

az elastic-san show \
--name <elastic-san-name> \
--resource-group <resource-group-name>

To list all Elastic SAN resources in your subscription, use:

az elastic-san list

References and useful links #

Thank you for taking the time to read my post. I sincerely hope that you find it helpful.