Home

Awesome

Charming

Nuget (with prereleases) Nuget

If you are someone who is comfortable using C# and are looking to avoid labouring with the cumbersome json syntax of an ARM template, then Charming is for you. 😎

What does it do?

You can define a template and the resources within it using C#, leveraging all its power and Charming will appropriately serialise the template to json. You can then deploy the outputted json template using any of the existing available methods such as the Azure CLI, Powershell or the Resource Manager REST API.

This library does not aim to provide functionality to create, modify or manage infrastructure. It does not handle any state or track any deployments. If you require such functionality, then you should check out other awesome tools like Terraform or Pulumi.

Features

Getting started

There are two NuGet packages available:

Install NuGet package:

Install-Package Charming.Types

or via the command line

dotnet add package Charming.Types

Usage

For detailed documentation and examples, check out the wiki.

Following example generates a template to deploy a storage account with a blob service and multiple containers:

// Define a storage account
var storage = new StorageAccount("samplestorage")
{
    Kind = "BlobStorage",
    Sku = new Sku { Name = "Standard_LRS" },
    Properties = new StorageAccountProperties { AccessTier = "Hot" },
};

// Container names - perhaps loaded from external configuration
var containers = new[] { "container1", "container2", "container3" };

// Define blob service with containers
var blobService = new StorageAccountBlobService("default")
    .WithResources(
        containers.Select(name => new StorageAccountBlobServiceContainer(name)));

// Add blob service as a child resource to storage
storage.Resources.Add(blobService);

// Create a resource group level deployment template
var template = new ResourceGroupDeploymentTemplate()
    .WithResources(storage);

// Generate json and write to a file that can be used for deployment
File.WriteAllText("azuredeploy.json", template.ToJson());

Add the following using directives for the example above:

using System.IO;
using System.Linq;
using Charming;
using Charming.Types.Storage;

Contributing

All contributions and feedback are welcome and highly appreciated. You can suggest and help develop new features, fix bugs or improve documentation.

Considering that Charming focusses mainly on helping generate ARM templates, new features must aim to: