With the release of [Pulumi for .NET preview](/blog/pulumi-dotnet-core/), we've open the doors to [infrastructure as code](/what-is/what-is-infrastructure-as-code/) to even more developers and operators. Millions of .NET developers can now use their favorite languages and open source ecosystems to build modern, cloud native applications. We've added support for C#, F#, and Visual Basic. Because .NET Core is available on Windows, Linux, and macOS, you have a choice of platforms to use.
You can create cloud resources by writing Microsoft .NET Core programs to build and deploy cloud resources to a wide variety of clouds, including Azure, AWS, GCP and more. On Azure, you can manage resources like AKS Clusters, Functions, Azure App Services, Virtual Machines, Cosmos DBs, KeyVaults, and much, much more. Let's take a first look at Pulumi for .NET by deploying an application on Azure.
With Pulumi, .NET developers can create, deploy and manage cloud infrastructure using C#, F#, or Visual Basic .NET. This results in increased productivity for developers because they can use the features of their IDEs such as auto-completion, error checking with red markers, build error messages, refactoring tools, and package managers. Developers can reference any NuGet library compatible with .NET Core 3.1.
Operators can use the `pulumi` CLI or CI/CD integrations to maintain and version infrastructure in a repository resulting in predictable and reliable deployments. Regardless of your cloud architecture, whether it includes containers, serverless function or static websites, Pulumi lets you build modern, reliable, and scalable applications. Your pipeline is part of your product.
You can accomplish all of this without having to learn a JSON or YAML DSL or script low-level CLI commands. With Pulumi, developers and operators have a shared foundation for building modern applications.
Pulumi is declarative even though it uses general purpose programming languages. It does this by specifying a set of resources, and the Pulumi engine orchestrates the CRUD operations to build and deploy infrastructure.
A Pulumi project uses a .NET Core console application to build infrastructure. To illustrate how this is accomplished, let's create an Azure App Service with an SQL database. The first step is to make sure that your environment meets the prerequisites:
There are four files in the Pulumi project, the `Azure.Appservice.csproj` which sets the .NET SDK and the Pulumi packages for the project. `Pulumi.yaml` holds project parameters such as name and runtime. The `Pulumi.dev.yaml` file holds the database password. `SharedAccessSignature.cs` contains a helper function to generate storage blob access URLs with SAS tokens in them. It demonstrates that you can add custom code inside your Pulumi program. `Program.cs` is the main program for declaring resources.
1. Define the SQL Server password (make it complex enough to satisfy [Azure policy](https://docs.microsoft.com/en-us/azure/active-directory/authentication/concept-sspr-policy#password-policies-that-only-apply-to-cloud-user-accounts)):
> If you are using a free Azure account, some regions do not allow creating services if they are too busy. You might have to try a different [Azure location](https://azure.microsoft.com/en-us/global-infrastructure/locations/). You must tear down the stack resources to update the project's location information.
The endpoint is one of the outputs that the stack returns. Check the deployed website endpoint by querying the stack and using curl to retrieve the web page.
From there, feel free to experiment. Simply making edits and running `pulumi up` will incrementally update your stack. Once finished, tear down your stack's resources by destroying and removing it:
First, we created a [resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/overview#resource-groups), a [storage account](https://docs.microsoft.com/en-us/azure/storage/common/storage-redundancy-lrs), and an [application service plan](https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans) for our application:
The `wwwroot` directory containing the `index.html` page into is added to the storage account we created previously. The `SharedAccessSignature.cs` code is a helper function to generate storage blob access URLs with [SAS tokens](https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview). This shows how you can add custom code inside your Pulumi program.
return $"Server= tcp:{server}.database.windows.net;initial catalog={database};userID={username};password={pwd};Min Pool Size=0;Max Pool Size=30;Persist Security Info=true;";
In this example, we declared resources for a website and a database using C# and the Pulumi engine deployed them to Azure. To get started with infrastructure as code, download [Pulumi](/docs/install/) to build and deploy modern applications using .NET Core.