Azure YAML Starter
A minimal Azure Native Pulumi YAML 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-yamlmkdir my-project; cd my-projectpulumi new azure-yamlThe 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 resources it declares.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.
Take a moment to open them up and have a look. Here’s what’s in Pulumi.yaml:
name: my-projectdescription: A minimal Azure Native Pulumi YAML programruntime: yamlresources: # 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}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 Pulumi.yaml, add this below the storage account:
resources: # ... container: type: azure-native:storage:BlobContainer properties: resourceGroupName: ${resourceGroup.name} accountName: ${sa.name} hello: type: azure-native:storage:Blob properties: resourceGroupName: ${resourceGroup.name} accountName: ${sa.name} containerName: ${container.name} blobName: hello.txt type: Block source: fn::stringAsset: Hello, Pulumi!
outputs: # ... 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