Azure TypeScript Starter
A minimal Azure Native TypeScript Pulumi program
Before you begin#
For this walkthrough, you'll need:
- The Pulumi CLI
- The Azure CLI (optional, but recommended and used in this guide)
- Permission to manage Azure Storage
Create a new project#
This starter creates an Azure resource group with a storage account in it and exports the storage account’s name.
mkdir my-project; cd my-projectpulumi new azure-typescriptmkdir my-project; cd my-projectpulumi new azure-typescriptThe 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:
| Key | Description | Default |
|---|---|---|
| azure-native:location | The Azure location to use | WestUS2 |
pulumi config set
:
pulumi config set azure-native:location <value>pulumi config set azure-native:location "<value>"Review the code#
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tscontains 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:
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 Groupconst resourceGroup = new resources.ResourceGroup("resourceGroup");
// Create an Azure Storage Accountconst storageAccount = new storage.StorageAccount("sa", { resourceGroupName: resourceGroup.name, sku: { name: storage.SkuName.Standard_LRS, }, kind: storage.Kind.StorageV2,});
// Export the storage account nameexport 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.
pulumi uppulumi upWhen 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:
az storage account show --name $(pulumi stack output storageAccountName) --query primaryEndpoints.blob --output tsvaz storage account show --name $(pulumi stack output storageAccountName) --query primaryEndpoints.blob --output tsvNeed help?
If pulumi up asks you to run az login, or says your sign-in has expired, sign in again:
az loginaz loginStill 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:
pulumi uppulumi upThen read the file back from the storage account. It prints Hello, Pulumi!:
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-progressaz 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-progressTo see what else you can add, browse the Azure Native provider in the Pulumi Registry.
Cleaning up#
You can destroy the stack and all of its infrastructure with pulumi destroy, then remove the stack with pulumi stack rm:
pulumi destroypulumi stack rmpulumi destroypulumi stack rm