2023-05-15 15:25:28 -07:00

7.2 KiB

title_tag, title, layout, date, draft, description, meta_desc, index, estimated_time, meta_image, authors, tags
title_tag title layout date draft description meta_desc index estimated_time meta_image authors tags
Creating a Pulumi Project | Learn Pulumi Creating a Pulumi Project topic 2021-09-10T12:00:00-05:00 false To get started, create your first Pulumi project using the CLI. Learn how to get started with Pulumi by creating your first Pulumi project using the Pulumi CLI in this tutorial. 0 5 meta.png
sophia-parafina
laura-santamaria
fundamentals
projects
docker

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:

{{< chooser language "typescript,python,go,csharp,java,yaml" / >}}

{{% choosable language typescript %}}

$ pulumi new typescript -y

{{% /choosable %}}

{{% choosable language python %}}

$ pulumi new python -y

{{% /choosable %}}

{{% choosable language go %}}

$ pulumi new go -y

{{% /choosable %}}

{{% choosable language csharp %}}

$ pulumi new csharp -y

{{% /choosable %}}

{{% choosable language java %}}

$ pulumi new java-gradle --dir my_first_app --name my_first_app -y

{{% /choosable %}}

{{% choosable language yaml %}}

$ pulumi new yaml -y

{{% /choosable %}}

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

{{% choosable language typescript %}}

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'

{{% /choosable %}}

{{% choosable language python %}}

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'

{{% /choosable %}}

{{% choosable language go %}}

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'

{{% /choosable %}}

{{% choosable language csharp %}}

Created project 'my_first_app'

Created stack 'dev'

Installing dependencies...

#...

Finished installing dependencies

Your new project is ready to go! ✨

To perform an initial deployment, run 'pulumi up'

{{% /choosable %}}

{{% choosable language java %}}

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'

{{% /choosable %}}

{{% choosable language yaml %}}

Created project 'my_first_app'
# ...
Created stack 'dev'

Your new project is ready to go! ✨

To perform an initial deployment, run 'pulumi up'

{{% /choosable %}}

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
  • {{< choosable language typescript >}}

  • {{< langfile >}}: your program's main entrypoint file
  • package.json: your project's Node.js dependency information
  • {{< /choosable >}}

    {{< choosable language python >}}

  • {{< langfile >}}: your program's main entrypoint file
  • requirements.txt: your project's Python dependency information
  • venv: a virtualenv for your project
  • {{< /choosable >}}

    {{< choosable language go >}}

  • go.mod: a file that describes the Go program's properties
  • go.sum: a generated file that maintains the checksums for the packages imported by the Go program
  • {{< langfile >}}: your program's main entrypoint file
  • {{< /choosable >}}

    {{< choosable language java >}}

  • {{< langfile >}}: your program's main entrypoint file
  • 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
  • {{< /choosable >}}

{{% choosable language yaml %}}

For YAML, your {{< langfile >}} is also your program's main entrypoint file.

{{% /choosable %}}

Use the command cat{{< langfile >}} to explore the contents of your project's empty program:

{{< chooser language "typescript,python,go,java,yaml" / >}}

{{% choosable language typescript %}}

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

{{% /choosable %}}

{{% choosable language python %}}

"""A Python Pulumi program"""

import pulumi

{{% /choosable %}}

{{% choosable language go %}}

package main

import (
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		return nil
	})
}

{{% /choosable %}}

{{% choosable language java %}}

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"));
        });
    }
}

{{% /choosable %}}

{{% choosable language yaml %}}

name: my_first_app
runtime: yaml
description: A minimal Pulumi YAML program

configuration: {}
variables:     {}
resources:     {}
outputs:       {}

{{% /choosable %}}

Feel free to explore the other files.

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