Trusted answers to developer questions

How to create a new project in Pulumi

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

Creating a new project

In order to create a new project, we would first create a tutorials folder so that we can create our Pulumi project inside. To do so, run these commands in your terminal:

mkdir tutorials && cd tutorials && pulumi new azure-typescript

As Pulumi creates a project for you, the CLI will walk you through a few steps. You can choose to set your project name, description, stack name, and azure location, or you can use the defaults that Pulumi provides by hitting the Enter key. It’s totally up to you.

Once you have this set up, you should have an index.ts, Pulumi.yaml, & Pulumi.dev.yaml (If you didn’t change the stack name).

Let’s go through what each of these files actually does:

  1. index.ts – This is the entry point of our code. If we declare any Azure resources in this file, Pulumi will create it for us.
  2. Pulumi.yaml – This defines the Pulumi project.
  3. Pulumu.dev.yaml – This file contains configuration values for the dev stack. You could think about stacks the way you would think about your environments. You could create a staging stack and have those config values map to your staging environment, you could also do that for your local environment and your production environment.

Creating resources for our Azure function app

To create our Azure function app, we would need to create a few resources:

  1. Resource group
  2. App service plan
  3. Storage account
  4. Function app

The code snippet below allows us to use Pulumi and Typescript to declare these Azure resources.

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const environment = pulumi.getStack();
const location = "WestEurope";
const resourceGroupName = "tutorial-rg";
const appservicePlanName = "tutorial-plan";
const storageAccountName = "tutorialstore";
const functionAppName = "tutorial-app";
// Create Resource Group
export const resourceGroup = new azure.core.ResourceGroup(resourceGroupName,
{
location,
name: resourceGroupName,
tags: {
environment
}
});
// Create app service plan
export const asp = new azure.appservice.Plan(appservicePlanName, {
kind: "App",
location,
name: appservicePlanName,
resourceGroupName: resourceGroup.name,
sku: {
size: "S1",
tier: "Premium V2"
},
maximumElasticWorkerCount: 1
});
// Storage account for the function app
export const store = new azure.storage.Account(storageAccountName, {
name: storageAccountName,
accountReplicationType: "LRS",
accountTier: "Standard",
location: resourceGroup.location,
accountKind: "StorageV2",
resourceGroupName: resourceGroup.name,
tags: {
environment
}
});
// Create function app
export const app = new azure.appservice.FunctionApp(functionAppName, {
appServicePlanId: asp.id,
location: resourceGroup.location,
resourceGroupName: resourceGroup.name,
storageAccountName: store.name,
storageAccountAccessKey: store.primaryAccessKey,
identity: {
type: "SystemAssigned"
},
appSettings: {
CLOUD_SERVICE_CONFIG: environment
},
siteConfig: {
alwaysOn: true,
use32BitWorkerProcess: false,
websocketsEnabled: false
},
version: "~3",
tags: {
environment
}
});

To create the resources you just declared, run the command below in your terminal (make sure you are still logged in to pulumi and you are in your pulumi project directory):

pulumi up 

It will do a preview of all the resources to be created, and ask if you would like to continue. You can select yes.

You have finally created Azure resources using Pulumi. You can go to your Azure portal to confirm that they are there.

widget

Don’t forget to delete those Azure resources when you are done playing around with your new shiny toy 😊😊. You can do this by running:

pulumi destroy

If you like this tutorial and you want me to do more, please let me know.

RELATED TAGS

azure
pulumi

CONTRIBUTOR

Adora Nwodo
Attributions:
  1. undefined by undefined
Did you find this helpful?