Get started with Pulumi and Azure
Create a new project
A project is a program in your chosen language that defines a collection of related cloud resources. In this step, you will create a new project.
Initializing your project
Each project lives in its own directory. Create a new one:
$ mkdir quickstart
> mkdir quickstart
Change into the new directory:
$ cd quickstart
> cd quickstart
Now initialize a new Pulumi project for Azure using the pulumi new command:
$ pulumi new azure-typescript
> pulumi new azure-typescript
$ pulumi new azure-python
> pulumi new azure-python
$ pulumi new azure-csharp
> pulumi new azure-csharp
$ pulumi new azure-go
> pulumi new azure-go
$ pulumi new azure-java
> pulumi new azure-java
$ pulumi new azure-yaml
> pulumi new azure-yaml
The pulumi new command interactively walks through initializing a new project, as well as creating a
stack and configuring it. A stack is an instance of your
project and you may have many of them – like dev, staging, and prod – each with different configuration settings.
You will be prompted for configuration values such as an Azure location. You can hit ENTER to accept the default of WestUS2,
or can type in another value such as eastus:
azure-native:location: The Azure location to use: (WestUS2) eastus
After some dependency installations from npm, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
After the command completes, the project and stack will be ready.
Review your new project’s contents
If you list the contents of your directory, you’ll see some key files:
src/main/java/myprojectis the project’s Java package root
contains your project’s main code that declares an Azure resource group and storage accountindex.jsindex.tsmain.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlPulumi.yamlis a project file containing metadata about your project like its name
Pulumi.yamlis a project file containing metadata about your project, like its name, as well as declaring your project’s resources
Pulumi.dev.yamlcontains configuration values for the stack you just initialized
Now examine the code in index.jsindex.ts__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yaml
import * as pulumi from "@pulumi/pulumi";
import * as resources from "@pulumi/azure-native/resources";
import * as storage from "@pulumi/azure-native/storage";
// Create an Azure Resource Group
const resourceGroup = new resources.ResourceGroup("resourceGroup");
// Create an Azure resource (Storage Account)
const storageAccount = new storage.StorageAccount("sa", {
resourceGroupName: resourceGroup.name,
sku: {
name: storage.SkuName.Standard_LRS,
},
kind: storage.Kind.StorageV2,
});
// Export the storage account name
export const storageAccountName = storageAccount.name;
"""An Azure RM Python Pulumi program"""
import pulumi
from pulumi_azure_native import storage
from pulumi_azure_native import resources
# Create an Azure Resource Group
resource_group = resources.ResourceGroup("resource_group")
# Create an Azure Storage Account
account = storage.StorageAccount(
"sa",
resource_group_name=resource_group.name,
sku={
"name": storage.SkuName.STANDARD_LRS,
},
kind=storage.Kind.STORAGE_V2,
)
# Export the storage account name
pulumi.export("storage_account_name", account.name)
package main
import (
"github.com/pulumi/pulumi-azure-native-sdk/resources/v2"
"github.com/pulumi/pulumi-azure-native-sdk/storage/v2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create an Azure Resource Group
resourceGroup, err := resources.NewResourceGroup(ctx, "resourceGroup", nil)
if err != nil {
return err
}
// Create an Azure resource (Storage Account)
storageAccount, err := storage.NewStorageAccount(ctx, "sa", &storage.StorageAccountArgs{
ResourceGroupName: resourceGroup.Name,
Sku: &storage.SkuArgs{
Name: pulumi.String("Standard_LRS"),
},
Kind: pulumi.String("StorageV2"),
})
if err != nil {
return err
}
// Export the storage account name
ctx.Export("storageAccountName", storageAccount.Name)
return nil
})
}
using Pulumi;
using Pulumi.AzureNative.Resources;
using Pulumi.AzureNative.Storage;
using Pulumi.AzureNative.Storage.Inputs;
using System.Collections.Generic;
return await Pulumi.Deployment.RunAsync(() =>
{
// Create an Azure Resource Group
var resourceGroup = new ResourceGroup("resourceGroup");
// Create an Azure resource (Storage Account)
var storageAccount = new StorageAccount("sa", new StorageAccountArgs
{
ResourceGroupName = resourceGroup.Name,
Sku = new SkuArgs
{
Name = SkuName.Standard_LRS
},
Kind = Kind.StorageV2
});
// Export the storage account name
return new Dictionary<string, object?>
{
["storageAccountName"] = storageAccount.Name
};
});
package myproject;
import com.pulumi.Pulumi;
import com.pulumi.azurenative.resources.ResourceGroup;
import com.pulumi.azurenative.storage.StorageAccount;
import com.pulumi.azurenative.storage.StorageAccountArgs;
import com.pulumi.azurenative.storage.enums.Kind;
import com.pulumi.azurenative.storage.enums.SkuName;
import com.pulumi.azurenative.storage.inputs.SkuArgs;
public class App {
public static void main(String[] args) {
Pulumi.run(ctx -> {
var resourceGroup = new ResourceGroup("resourceGroup");
var storageAccount = new StorageAccount("sa", StorageAccountArgs.builder()
.resourceGroupName(resourceGroup.name())
.sku(SkuArgs.builder()
.name(SkuName.Standard_LRS)
.build())
.kind(Kind.StorageV2)
.build());
ctx.export("storageAccountName", storageAccount.name());
});
}
}
name: quickstart
runtime: yaml
description: A minimal Azure Native Pulumi YAML program
resources:
# Create an Azure Resource Group
resourceGroup:
type: azure-native:resources:ResourceGroup
# Create an Azure Storage Account
sa:
type: azure-native:storage:StorageAccount
properties:
resourceGroupName: ${resourceGroup.name}
sku:
name: Standard_LRS
kind: StorageV2
outputs:
# Export the storage account name
storageAccountName: ${sa.name}
The program declares an Azure Resource Group and Storage Account resources and exports the storage account’s name as a stack output. Notice that the storage account name is an output property that Azure assigns at deployment time. Now you’re ready for your first deployment!
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.
