Creating a Pulumi Project

Infrastructure in Pulumi is organized into projects. In the Pulumi ecosystem, a project represents a Pulumi program that, when run, declares the desired infrastructure for Pulumi to manage. The program has corresponding stacks, or isolated, independently configurable instances of your Pulumi program. We’ll talk more about stacks later in the Building with Pulumi pathway.

Create a directory

Each Pulumi project lives in its own directory. Create one now and change into it by running these commands in your terminal:

mkdir my_first_app
cd my_first_app

Pulumi will use the directory name as your project name by default. To create an independent project, name the directory differently.

Initialize your project

Since a Pulumi project is just a directory with some files in it, it is possible for you to create a new one by hand. The pulumi new command-line interface (CLI) command, however, automates the process and ensures you have everything you need, so let’s use that command. The -y flag answers “yes” to the prompts to create a default project:

$ pulumi new typescript -y
$ pulumi new python -y
$ pulumi new java-gradle --dir my_first_app --name my_first_app -y
$ pulumi new yaml -y

This command prints output similar to the following example with a bit more information and status as it goes:

Created project 'my_first_app'
# ...

Installing dependencies...
# ...

Finished installing dependencies

Your new project is ready to go! ✨

To perform an initial deployment, run 'pulumi up'
Created project 'my_first_app'
# ...
Created stack 'dev'

Creating virtual environment...
# ...
Finished creating virtual environment

Updating pip, setuptools, and wheel in virtual environment...
# ...
Your new project is ready to go! ✨

To perform an initial deployment, run 'pulumi up'
Created project 'my_first_app'
# ...
Created stack 'dev'

Your new project is ready to go! ✨

To perform an initial deployment, run 'cd my_first_app', then, run 'pulumi up'
Created project 'my_first_app'
# ...
Created stack 'dev'

Your new project is ready to go! ✨

To perform an initial deployment, run 'pulumi up'

This command creates all the files we need, initializes a new stack named dev (an instance of our project), and installs any necessary dependencies.

Inspect your new project

The basic project created by pulumi new is comprised of multiple files:

  • Pulumi.yaml: your project’s metadata, containing its name and language
  • index.js index.ts __main__.py main.go MyStack.cs Program.fs MyStack.vb App.java Pulumi.yaml : your program’s main entrypoint file
  • package.json: your project’s Node.js dependency information
  • requirements.txt: your project’s Python dependency information
  • venv: a virtualenv for your project
  • settings.gradle: your project’s Gradle settings
  • app/: the app directory generated for Java, which includes the following files:
    • build.gradle: your project’s build information for Gradle
    • src/main/java/my_first_app/: the directory that holds your main entrypoint file

Use the command cat index.js index.ts __main__.py main.go MyStack.cs Program.fs MyStack.vb App.java Pulumi.yaml to explore the contents of your project’s empty program:

import * as pulumi from "@pulumi/pulumi";
"""A Python Pulumi program"""

import pulumi
package my_first_app;

import com.pulumi.Pulumi;
import com.pulumi.core.Output;

public class App {
    public static void main(String[] args) {
        Pulumi.run(ctx -> {
            ctx.export("exampleOutput", Output.of("example"));
            return ctx.exports();
        });
    }
}
description: ${DESCRIPTION}
runtime: yaml
template:
    description: A minimal Pulumi YAML program
configuration: {}
variables: {}
resources: {}
outputs: {}

Feel free to explore the other files.

Let’s move on to creating your first real bit of infrastructure with Pulumi: some Docker images.