BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Pulumi: Cloud Infrastructure with .NET Core

Pulumi: Cloud Infrastructure with .NET Core

Earlier this month, Pulumi announced the addition of .NET Core to their supported languages. Pulumi is an open-source tool that allows the creation, deployment, and management of infrastructure as code on multiple cloud providers, similarly to HashiCorp Terraform.

Infrastructure as Code (IaC) is the process of managing infrastructure in a descriptive model using configuration files, used by DevOps in conjunction with Continuous Delivery (CD). Most major cloud providers offer their own IoC solution, usually based on JSON or YAML configuration files. These files can be then be integrated into the development process, being maintained and versioned in code repositories. Examples of IaC tools include Chef, Puppet, AWS CloudFormation, and Azure Resource Manager (ARM).

Launched last year, Pulumi is a relatively new player on the IaC scene. According to their website:

The Pulumi Cloud Development Platform is a combination of tools, libraries, runtime, and service that delivers a consistent development and operational control plane for cloud-native infrastructure. Not only does Pulumi enable you to manage your infrastructure as code, but it also lets you define and manage your infrastructure using real programming languages (and all of their supporting tools) instead of YAML.

Similarly to HashiCorp Terraform, Pulumi uses programs for partitioning, configuring, and scaling (provisioning) virtual environments. However, while in Terraform these programs are written in a custom domain-specific language (DSL), Pulumi's programs are written in general-purpose languages. The addition of .NET Core support allows Pulumi programs to be written using C#, VB.NET, or F#.

Using a general-purpose language allows the integration of IaC with the existing language ecosystem. In the case of .NET, the benefits include integration with existing IDEs (including Visual Studio and Visual Studio Code), NuGet support (both for using existing libraries and distributing IaC programs), and using standard compiler errors.

Using .NET to write IaC programs also allows the use of language-specific resources, such as LINQ and async code. The code excerpt below illustrates how an Azure CosmosDB can be created with a serverless Azure AppService FunctionApp that automatically scales alongside the database:

using System;
using System.Collections.Generic;

using Pulumi;
using Pulumi.Azure.AppService;
using Pulumi.Azure.Core;
using Pulumi.Azure.CosmosDB;

class Program
{
    static Task<int> Main(string[] args)
    {
        return Deployment.RunAsync(() => {
            var locations = new[] { "WestUS", "WestEurope", "SouthEastAsia" };

            var rg = new ResourceGroup("myapp-rg", new ResourceGroupArgs {
                Location = locations[0],
            });

            var app = new CosmosApp("myapp", new CosmosAppArgs {
                 ResourceGroup = resourceGroup,
                 Locations = locations,
                 DatabaseName = "pricedb",
                 ContainerName = "prices",
                 Factory = (location, db) => {
                     var func = new ArchiveFunctionApp("myapp-func",
                          new ArchiveFunctionAppArgs {
                              Location = location,
                              Archive = new FileArchive("app"),
                              AppSettings = new Dictionary<string, string> {
                                  ["COSMOSDB_ENDPOINT"] = db.Endpoint,
                              },
                          },
                      );
                      return func.App.ID;
                 },
            });
        });
    }

    // Definitions of CosmosApp and ArchiveFunctionApp elided for brevity.
    // Actual runtime application code is stored in the "app" directory.
    // See link to the full example at the end of this article.
}

(source: original announcement)

A full CosmosApp example can be found here. In addition to .NET, Pulumi also supports JavaScript, TypeScript, Python, and Go. A full list of all supported cloud providers can be found here. Pulumi is also open source on GitHub.

 

 

Rate this Article

Adoption
Style

BT