Skip to content

Projects ​

A Pulumi project is any folder that contains a Pulumi.yaml project file. At runtime, the nearest parent folder containing a Pulumi.yaml file determines the current project. Projects are created with the pulumi new command.

The project file (Pulumi.yaml) ​

The project file specifies which runtime to use and determines where to look for the program that should be executed during deployments. Supported runtimes are nodejs, python, dotnet, go, java, yaml, and hcl.

Project files also contain metadata about your project. The project file must begin with a capital P, although either .yml or .yaml extension will work.

A typical Pulumi.yaml file looks like the following. The runtime value depends on the language you choose:

yaml
name: webserver
runtime: nodejs
description: A minimal Pulumi program.

Each language has its own conventions for locating the program's entrypoint. For TypeScript, the working directory should contain a package.json file that points to an entrypoint such as index.ts. For Python, the entrypoint is a __main__.py file. Go, .NET, and Java follow the conventions of their respective build tools. For HCL, the working directory should contain one or more .tf files.

The following are other examples of Pulumi.yaml files that define project configurations for other use cases.

Compiled languages with a pre-built executable ​

For Go, .NET, and Java, you can point the runtime at a pre-built executable or assembly with the binary option. This skips the build step at deployment time:

Inline resources with the YAML runtime ​

A Pulumi.yaml file for a YAML program can include its resources inline:

yaml
name: my-project
runtime: yaml
resources:
  bucket:
    type: aws:s3:Bucket

For more information on valid Pulumi project metadata, see the Pulumi.yaml reference.

Project-relative paths ​

When your Pulumi program refers to resources in the local filesystem, paths are always relative to the working directory. In the following example, the aws.ecr.Image resource refers to a subfolder of the working directory named app that contains a Dockerfile:

ts
import * as pulumi from "@pulumi/pulumi";
import * as awsx from "@pulumi/awsx";

const repository = new awsx.ecr.Repository("repository", {
    forceDelete: true,
});

const image = new awsx.ecr.Image("image", {
    repositoryUrl: repository.url,
    context: "./app",
    platform: "linux/amd64",
});

export const url = repository.url;

Root-relative paths ​

You can get the directory containing the Pulumi.yaml file, which may differ from your working directory if the project sets a main option (see main attribute). Each language provides its own function to retrieve this path, as shown in the example below.

The path returned is an absolute path. When using this in resource properties, ensure it's relative to the working directory. This prevents diffs from running the project on multiple machines with different roots.

ts
import * as awsx from "@pulumi/awsx";
import * as pulumi from "@pulumi/pulumi";
import { join, relative } from "path";

const root = pulumi.getRootDirectory();
const cwd = process.cwd();
const appPath = join(root, "app");
const relativePath = relative(cwd, appPath);

const repository = new awsx.ecr.Repository("repository", {
    forceDelete: true,
});

const image = new awsx.ecr.Image("image", {
    repositoryUrl: repository.url,
    context: relativePath,
    platform: "linux/amd64",
});

export const url = repository.url;

Getting the current project programmatically ​

The

getProject

getProject

get_project

context.Project

Deployment.Instance.ProjectName

context.projectName()

pulumi.project

function returns the name of the currently deploying project. This can be useful for naming or tagging resources.
typescript
const project = pulumi.getProject();

To get the name of the currently deploying stack instead, see Getting the current stack programmatically.

Stack settings files ​

Each stack that is created in a project will have a file named Pulumi.<stackname>.yaml that contains the configuration specific to this stack. This file typically resides in the root of the project directory.

For stacks that are actively developed by multiple members of a team, the recommended practice is to check them into source control as a means of collaboration. Since secret values are encrypted, it is safe to check in these stack settings. When using ephemeral stacks, the stack settings are typically not checked into source control.

For more information about configuration and how to manage these files on the command line and programmatically, refer to the Configuration and Secrets documentation.

Content from the official Pulumi documentation (github.com/pulumi/docs).