chunliu / AzureDesignStudio.AzureResources

A collection of C# class libraries which contain the strong C# types for various of Azure resources.

Home Page:https://www.nuget.org/packages?q=AzureDesignStudio.AzureResources

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AzureDesignStudio.AzureResources

AzureDesignStudio.AzureResources is a side project of AzureDesignStudio. This project creates a collection of C# class libraries which contain the strong C# types for various of Azure resources. These libraries are used by AzureDesignStudio to serialize and deserialize Azure ARM templates and Bicep easily.

The C# code in this repo is auto-generated from the JSON schema of the ARM template by a tool, ArmTypeGenerator, which is another side project of AzureDesignStudio. Although the libraries are created for AzureDesignStudio, they can be used in other projects as well. If you need to create or parse ARM template or Bicep files with C# in your project, AzureDesignStudio.AzureResources can make your life much easier.

Features

  • Strong C# types for Azure Resources, up to date to the latest ARM template schema.
  • Serialize and deserialize with System.Text.Json easily.

How to use it

To use the libraries in your project, you can clone and build the code locally. But the most simple way is to get the corresponding nuget packages you need.

The libraries have been packaged into separate nuget packages. The naming convention is like, for example for types of Microsoft.Network resource provider, you can find them in AzureDesignStudio.AzureResources.Network package. For types of Microsoft.Web, they are in AzureDesignStudio.AzureResources.Web.

So instead of installing one big package for everything, you just need to install the package you need. For example, you can get types for Microsoft.Network resources by installing the package:

Install-Package AzureDesignStudio.AzureResources.Network -Version 0.3.0

To create an ARM template with code, you can do the following. You can find more samples in the samples folder.

VirtualNetworks vnet = new()
{
    Name = "Hello-vnet",
    Location = "eastus",
    Properties = new()
    {
        AddressSpace = new()
        {
            AddressPrefixes = new List<string> { "10.0.0.0/16" }
        }
    }
};

VirtualNetworksSubnets subnet = new()
{
    Name = $"{vnet.Name}/subnet1",
    Properties = new()
    {
        AddressPrefix = "10.0.0.0/24"
    },
};

DeploymentTemplate deploymentTemplate = new()
{
    Schema = "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    ContentVersion = "1.0.0.0",
    Resources = new List<ResourceBase> { vnet, subnet }
};

var template = JsonSerializer.Serialize(deploymentTemplate,
    new JsonSerializerOptions(JsonSerializerDefaults.Web)
    {
        DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
        Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
        WriteIndented = true,
        Converters = { new ResourceBaseJsonConverter() }
    });

Console.Write(template);

Contributions

Since the code is auto generated by a tool, manual editing would not be accepted. But if you have any feedback or suggestions, please feel free to create an issue. I will see if it can be addressed by the tool or not.

Disclaimer

This is a personal project without any warranty. It is neither an official product from Microsoft nor supported by Microsoft. Use it at your own risk.

About

A collection of C# class libraries which contain the strong C# types for various of Azure resources.

https://www.nuget.org/packages?q=AzureDesignStudio.AzureResources

License:MIT License


Languages

Language:C# 100.0%