2021-11-08 16:04:20 -06:00
|
|
|
---
|
2023-03-14 11:25:48 -07:00
|
|
|
title_tag: Creating a Pulumi Project | Learn Pulumi
|
2021-11-08 16:04:20 -06:00
|
|
|
title: "Creating a Pulumi Project"
|
|
|
|
layout: topic
|
|
|
|
date: 2021-09-10T12:00:00-05:00
|
|
|
|
draft: false
|
|
|
|
description: To get started, create your first Pulumi project using the CLI.
|
2023-03-14 11:25:48 -07:00
|
|
|
meta_desc: Learn how to get started with Pulumi by creating your first Pulumi project using the Pulumi CLI in this tutorial.
|
2021-11-08 16:04:20 -06:00
|
|
|
index: 0
|
|
|
|
estimated_time: 5
|
|
|
|
meta_image: meta.png
|
|
|
|
authors:
|
|
|
|
- sophia-parafina
|
|
|
|
- laura-santamaria
|
|
|
|
tags:
|
|
|
|
- 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
|
2022-10-26 07:22:15 -07:00
|
|
|
Pulumi](/learn/building-with-pulumi) pathway.
|
2021-11-08 16:04:20 -06:00
|
|
|
|
|
|
|
## 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:
|
|
|
|
|
|
|
|
```bash
|
2022-05-03 21:23:32 -07:00
|
|
|
mkdir my_first_app
|
|
|
|
cd my_first_app
|
2021-11-08 16:04:20 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
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
|
2022-02-10 08:46:56 -08:00
|
|
|
you need, so let's use that command. The `-y` flag answers "yes" to the prompts to
|
2021-11-08 16:04:20 -06:00
|
|
|
create a default project:
|
|
|
|
|
2023-02-28 09:12:01 +00:00
|
|
|
{{< chooser language "typescript,python,go,csharp,java,yaml" / >}}
|
2022-02-10 08:46:56 -08:00
|
|
|
|
|
|
|
{{% choosable language typescript %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ pulumi new typescript -y
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
2021-11-08 16:04:20 -06:00
|
|
|
|
|
|
|
{{% choosable language python %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ pulumi new python -y
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
2022-12-19 10:14:04 -07:00
|
|
|
{{% choosable language go %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ pulumi new go -y
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
2023-02-28 09:12:01 +00:00
|
|
|
{{% choosable language csharp %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ pulumi new csharp -y
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
2022-05-03 21:23:32 -07:00
|
|
|
{{% choosable language java %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ pulumi new java-gradle --dir my_first_app --name my_first_app -y
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
{{% choosable language yaml %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ pulumi new yaml -y
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
2021-11-08 16:04:20 -06:00
|
|
|
This command prints output similar to the following example with a bit more
|
2022-02-10 08:46:56 -08:00
|
|
|
information and status as it goes:
|
|
|
|
|
|
|
|
{{% choosable language typescript %}}
|
|
|
|
|
|
|
|
```bash
|
2022-05-03 21:23:32 -07:00
|
|
|
Created project 'my_first_app'
|
|
|
|
# ...
|
2022-02-10 08:46:56 -08:00
|
|
|
|
|
|
|
Installing dependencies...
|
2022-05-03 21:23:32 -07:00
|
|
|
# ...
|
2022-02-10 08:46:56 -08:00
|
|
|
|
|
|
|
Finished installing dependencies
|
|
|
|
|
|
|
|
Your new project is ready to go! ✨
|
|
|
|
|
|
|
|
To perform an initial deployment, run 'pulumi up'
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
{{% choosable language python %}}
|
2021-11-08 16:04:20 -06:00
|
|
|
|
|
|
|
```bash
|
2022-05-03 21:23:32 -07:00
|
|
|
Created project 'my_first_app'
|
|
|
|
# ...
|
2021-11-08 16:04:20 -06:00
|
|
|
Created stack 'dev'
|
|
|
|
|
|
|
|
Creating virtual environment...
|
2022-05-03 21:23:32 -07:00
|
|
|
# ...
|
2021-11-08 16:04:20 -06:00
|
|
|
Finished creating virtual environment
|
|
|
|
|
|
|
|
Updating pip, setuptools, and wheel in virtual environment...
|
2022-05-03 21:23:32 -07:00
|
|
|
# ...
|
|
|
|
Your new project is ready to go! ✨
|
|
|
|
|
|
|
|
To perform an initial deployment, run 'pulumi up'
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
2022-12-19 10:14:04 -07:00
|
|
|
{{% choosable language go %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
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 %}}
|
|
|
|
|
2023-02-28 09:12:01 +00:00
|
|
|
{{% choosable language csharp %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
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 %}}
|
|
|
|
|
2022-05-03 21:23:32 -07:00
|
|
|
{{% choosable language java %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
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 %}}
|
|
|
|
|
|
|
|
```bash
|
|
|
|
Created project 'my_first_app'
|
|
|
|
# ...
|
|
|
|
Created stack 'dev'
|
|
|
|
|
2021-11-08 16:04:20 -06:00
|
|
|
Your new project is ready to go! ✨
|
|
|
|
|
|
|
|
To perform an initial deployment, run 'pulumi up'
|
|
|
|
```
|
|
|
|
|
2022-02-10 08:46:56 -08:00
|
|
|
{{% /choosable %}}
|
|
|
|
|
2021-11-08 16:04:20 -06:00
|
|
|
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:
|
|
|
|
|
2022-12-19 10:14:04 -07:00
|
|
|
<!-- This section uses HTML due to an issue with langfile shortcode -->
|
|
|
|
<ul>
|
|
|
|
<li><code>Pulumi.yaml</code>: your project's metadata, containing its name and language</li>
|
2021-11-08 16:04:20 -06:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
{{< choosable language typescript >}}
|
2022-02-10 08:46:56 -08:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
<li>{{< langfile >}}: your program's main entrypoint file</li>
|
|
|
|
<li><code>package.json</code>: your project's Node.js dependency information</li>
|
2022-02-10 08:46:56 -08:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
{{< /choosable >}}
|
2022-02-10 08:46:56 -08:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
{{< choosable language python >}}
|
2022-02-10 08:46:56 -08:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
<li>{{< langfile >}}: your program's main entrypoint file</li>
|
|
|
|
<li><code>requirements.txt</code>: your project's Python dependency information</li>
|
|
|
|
<li><code>venv</code>: a <a href="https://pypi.org/project/virtualenv/">virtualenv</a> for your project</li>
|
2022-02-10 08:46:56 -08:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
{{< /choosable >}}
|
2022-02-10 08:46:56 -08:00
|
|
|
|
2022-12-19 10:14:04 -07:00
|
|
|
{{< choosable language go >}}
|
|
|
|
|
|
|
|
<li><code>go.mod</code>: a file that describes the Go program's properties</li>
|
|
|
|
<li><code>go.sum</code>: a generated file that maintains the checksums for the packages imported by the Go program</li>
|
|
|
|
<li>{{< langfile >}}: your program's main entrypoint file</li>
|
|
|
|
|
|
|
|
{{< /choosable >}}
|
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
{{< choosable language java >}}
|
2022-05-03 21:23:32 -07:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
<li>{{< langfile >}}: your program's main entrypoint file</li>
|
|
|
|
<li><code>settings.gradle</code>: your project's Gradle settings</li>
|
|
|
|
<li><code>app/</code>: the app directory generated for Java, which includes the following files:
|
|
|
|
<ul>
|
|
|
|
<li><code>build.gradle</code>: your project's build information for Gradle</li>
|
|
|
|
<li><code>src/main/java/my_first_app/</code>: the directory that holds your main entrypoint file</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
2022-05-03 21:23:32 -07:00
|
|
|
|
2022-09-01 10:35:26 -05:00
|
|
|
{{< /choosable >}}
|
2022-12-19 10:14:04 -07:00
|
|
|
</ul>
|
2022-05-03 21:23:32 -07:00
|
|
|
|
|
|
|
{{% choosable language yaml %}}
|
2022-09-01 10:35:26 -05:00
|
|
|
|
|
|
|
For YAML, your {{< langfile >}} is also your program's main entrypoint file.
|
|
|
|
|
2022-05-03 21:23:32 -07:00
|
|
|
{{% /choosable %}}
|
|
|
|
|
2022-02-10 08:46:56 -08:00
|
|
|
Use the command <code>cat</code>{{< langfile >}} to explore the contents of your
|
2021-11-08 16:04:20 -06:00
|
|
|
project's empty program:
|
|
|
|
|
2022-12-19 10:14:04 -07:00
|
|
|
{{< chooser language "typescript,python,go,java,yaml" / >}}
|
2022-02-10 08:46:56 -08:00
|
|
|
|
|
|
|
{{% choosable language typescript %}}
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
import * as pulumi from "@pulumi/pulumi";
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
2021-11-08 16:04:20 -06:00
|
|
|
|
|
|
|
{{% choosable language python %}}
|
|
|
|
|
|
|
|
```python
|
|
|
|
"""A Python Pulumi program"""
|
|
|
|
|
|
|
|
import pulumi
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
2022-12-19 10:14:04 -07:00
|
|
|
{{% choosable language go %}}
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
pulumi.Run(func(ctx *pulumi.Context) error {
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
2022-05-03 21:23:32 -07:00
|
|
|
{{% choosable language java %}}
|
|
|
|
|
|
|
|
```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 %}}
|
|
|
|
|
|
|
|
```yaml
|
2022-09-01 10:35:26 -05:00
|
|
|
name: my_first_app
|
2022-05-03 21:23:32 -07:00
|
|
|
runtime: yaml
|
2022-09-01 10:35:26 -05:00
|
|
|
description: A minimal Pulumi YAML program
|
|
|
|
|
2022-05-03 21:23:32 -07:00
|
|
|
configuration: {}
|
2022-09-01 10:35:26 -05:00
|
|
|
variables: {}
|
|
|
|
resources: {}
|
|
|
|
outputs: {}
|
2022-05-03 21:23:32 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
Feel free to explore the other files.
|
2021-11-08 16:04:20 -06:00
|
|
|
|
|
|
|
Let's move on to creating your first real bit of infrastructure with Pulumi:
|
|
|
|
some Docker images.
|
|
|
|
|
2023-05-15 15:25:28 -07:00
|
|
|
<!-- [^1]: [project](https://www.pulumi.com/docs/concepts/glossary/#project) -->
|
|
|
|
<!-- [^2]: [program](https://www.pulumi.com/docs/concepts/glossary/#program) -->
|
|
|
|
<!-- [^3]: [stack](https://www.pulumi.com/docs/concepts/glossary/#stack) -->
|