本月伊始,Pulumi宣布在他们支持的语言中新增了.NET Core。Pulumi是一个开源工具,支持在多个云供应商上以代码的形式创建,开发并管理基础架构,类似于HashiCorp Terraform。
架构即代码(IaC)就是使用配置文件以可描述的模型来管理架构的过程,通常与持续交付相结合用于DevOps。大部分主要的云供应商提供了他们自己的IaC解决方案,通常基于JSON或YAML配置文件。然后这些文件被集成到开发过程中,被包含在代码库中,并进行版本控制。IaC工具包括Chef,Puppet,AWS CloudFormation以及Azure Resource Manager(ARM)。
去年才推出,Pulumi在Iac领域可以说是初出茅庐。根据他们网站的说法:
“Pulumi云开发平台是一系列工具,库,运行时以及服务,为云原生基础架构提供一致的开发和运营控制平面,Pulumi不仅使您能够以代码形式管理基础结构,而且还允许您使用真正的编程语言(及其所有支持工具)而不是YAML来定义和管理基础结构。”
类似于HashiCorp Terraform,Pulumi使用程序对虚拟环境进行分区,配置和扩展。不同之处在于,在Terraform中这些程序是使用自定义的特定领域语言(DSL)编写的,Pulumi的程序使用通用语言。.NET Core的支持使得Pulumi程序可以使用C#,VB.NE或F#编写。
使用通用语言允许将IaC与现存的语言生态结合起来。就.NET而言,好处包括与已有的IDE(包括Visual Studio 和 Visual Studio Code)集成,NuGet支持(包括使用现有库以及发布Iac程序),并使用标准的编译错误。
使用.NET编写Iac程序还可以使用语言特定的资源,例如LINQ以及异步代码。下面的代码片段展示了如何使用一个无服务的Azure AppService FunctionApp创建一个Azure CosmosDB并根据数据库自动缩放:
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.
}
完整示例。
除了.NET,Pulumi还支持JavaScript,TypeScript,Python以及Go。Pulumi已经在GitHub上开源。