Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Azure TypeScript Starter

A minimal Azure Native TypeScript Pulumi program

Before you begin#

For this walkthrough, you'll need:

Create a new project#

This starter creates an Azure resource group with a storage account in it and exports the storage account’s name.

Terminal window
mkdir my-project; cd my-project
pulumi new azure-typescript

The pulumi new command walks you through creating and configuring the new project and stack. A stack is an instance of a project, and you can have many of them (dev, staging, prod), each with its own configuration settings. Depending on the language, you may also be asked for your preferred package manager or toolchain.

The template also asks for the Azure location you’d like to deploy into:

KeyDescriptionDefault
azure-native:locationThe Azure location to useWestUS2
You can change values like these later with pulumi config set :
Terminal window
pulumi config set azure-native:location <value>

Review the code#

When setup completes, you’ll see a few files:

  • Pulumi.yaml contains the project name and the language it’s written in.
  • Pulumi.dev.yaml contains the dev stack’s settings, including the values you just entered.
  • index.ts contains the program code that declares your cloud resources.

Take a moment to open them up and have a look. Here’s what’s in index.ts:

index.ts
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 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;

Deploy the project#

Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.

Pulumi adds a random suffix to most resource names, so the storage account sa gets a name like sa8deefa78. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.

Terminal window
pulumi up

When it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist. This program exports the storage account’s name. Read it any time with pulumi stack output <name>, or pass it to another command. This one prints the account’s blob endpoint:

Terminal window
az storage account show --name $(pulumi stack output storageAccountName) --query primaryEndpoints.blob --output tsv
Need help?

If pulumi up asks you to run az login, or says your sign-in has expired, sign in again:

Terminal window
az login

Still stuck? Let us know.

Customize the project#

Put a file in the storage account. In index.ts, add this below the storage account:

const container = new storage.BlobContainer("container", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
});
new storage.Blob("hello", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: container.name,
blobName: "hello.txt",
source: new pulumi.asset.StringAsset("Hello, Pulumi!"),
});
export const containerName = container.name;

Deploy again. The preview shows a container and a file to create:

Terminal window
pulumi up

Then read the file back from the storage account. It prints Hello, Pulumi!:

Terminal window
az storage blob download --account-name $(pulumi stack output storageAccountName) --container-name $(pulumi stack output containerName) --name hello.txt --auth-mode key --only-show-errors --no-progress

Cleaning up#

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure platform for humans and agents.