Pulumi Sample
Pulumi Sample
Christian Nunciato
This is a Leanpub book. Leanpub empowers authors and publishers with the
Lean Publishing process. Lean Publishing is the act of publishing an
in-progress ebook using lightweight tools and many iterations to get reader
feedback, pivot until you have the right book and build traction once you do.
Welcome! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Part 1: Foundations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Part 1: Foundations
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 1: Introducing Pulumi
• The parts of Pulumi, what they do, and how to use them
The trouble, of course, is that I’m a web developer, and you can’t get very far
with a web application without some kind of infrastructure. So for the majority
Chapter 1: Introducing Pulumi 3
of my career, I’ve had to contend with this reality, and it hasn’t always been fun.
Sometimes it has. But mostly, not so much.
But after years of frustration and toil, here’s what I’ve learned: with the right set
of tools, managing infrastructure can actually be a delightful experience, even
for a cranky developer like me. Pulumi, it turns out, is one of those tools.
Depending on your background, though, you might just be wondering why a tool
like Pulumi even exists in the first place. Why would anyone want to write code to
manage infrastructure? Isn’t it easier just to configure computers by hand? And
why should using a general-purpose language like TypeScript matter? Doesn’t
that make the process even more complicated?
Good questions all, and I’m glad that you asked them. Let’s begin, then, by taking
a step back and having a look at what led to the need for infrastructure as code to
begin with. And then later, you’ll meet Pulumi, and get a sense of what it is that
makes it so different.
Chapter 1: Introducing Pulumi 4
The cloud is a great and powerful thing: limitless computing available on demand,
and usable in so many ways it’s almost impossible to count them.
It’s also a huge, complex, and intimidating beast, and using it effectively can be
surprisingly difficult.
As you sketch out the details of this nascent little project, the application itself
seems fairly straightforward: to start, all you’ll need are a web app and a database,
so you opt to keep it simple and go with what you know: Express.js for the
application, say, and MySQL for the database. Easy enough.
For the infrastructure, though, you’re in much murkier territory. You know
you’ll need at least one server to host the application, and that a single server
Chapter 1: Introducing Pulumi 5
should probably suffice. But beyond that nebulous requirement — again, since
infrastructure isn’t your specialty — you aren’t quite sure how best to proceed.
But you’re committed, and AWS seems as safe a choice as any, so you decide to
roll forward and give it a shot. And on the whole, things go pretty well: with a
few button clicks, and a few hours spent sifting through docs and configuring
a new virtual machine, your shiny new dog-walking service is live, and people
are signing up. It’s an exciting time, both for you and for many a neighborhood
pooch. And before long, the service actually becomes rather popular.
A few months later, maybe, you get an email from an angry customer claiming
the website is down, and indeed you immediately confirm that’s the case — and
not just down, but gone: both virtual machines have somehow vanished from the
AWS Console, leaving you no choice but to build them all over again, from scratch
(and right now), to save your fledgling business.
Or maybe you’re faced with a different problem: the website’s become so popular
that you seem to be spending all of your time dealing with infrastructure —
spinning up new servers, patching old ones, rotating logs, and so on — and no
time developing new features for the site, which is, of course, the whole reason
you got into this project in the first place.
And this is just one website. Imagine trying to manage two or three others like
it, all by hand, using only the browser and the command line. And now, imagine
ten, or twenty. It’s a losing proposition: beyond the smallest of scales, managing
Chapter 1: Introducing Pulumi 6
servers by hand becomes a full-time job, and sooner or later, without some kind
of automation, it’s practically impossible.
• Hand-crafted servers are opaque. You can’t look at AWS Console, for
example, and easily discern the state of a given machine — what’s installed
on that machine, which versions of an application it’s currently hosting,
which upstream services the application relies on, and so on. The need for
this kind of information comes up a lot more often than you might think,
and to get it, you usually have to go poking around on the command line.
• Hand-crafted servers are unique snowflakes. Just like your laptop, a man-
ually configured machine is the product of countless ad hoc mutations over
time, which means you can’t just stamp out another copy when you need
one. And even if you could, any change to one of the copies would have to be
made to all of them, which is tedious, error-prone, and not the sort of work
most of us would enjoy doing with our time.
But here’s the thing: while it’s true that we humans aren’t very good at managing
computers by hand, we are pretty good at describing how a computer (or a lot of
computers) ought to be configured. It might take me the better part of a month,
for example, to provision and configure a hundred servers running my massively
popular dog-walking website — but it only it only takes me a few moments to
write I want a thousand servers running my dog-walking website, and only a few
moments more to express that in code, and let the computers handle the work
of provisioning and configuration for me.
Chapter 1: Introducing Pulumi 7
Most IaC tools fall into one of two categories. Configuration management tools
focus on managing the software and settings of an existing computer — a virtual
machine, say, or a “bare-metal” (i.e., physical) server installed in a data center.
These tools typically run on their target computers directly, as executable pro-
grams, and you can think of them as software-based stand-ins for the kinds of
tasks you might perform at the command-line: installing packages like Node.js,
creating user accounts, writing configuration files, or fetching source code to up-
date a web application. Popular configuration management tools include Ansible
(https://ansible.com), Chef (https://chef.io), Puppet (https://puppet.com), and
SaltStack (https://saltstack.com).
Provisioning tools, on the other hand — Pulumi falls into this category — are
responsible for creating cloud infrastructure from scratch. Their job is to com-
municate with cloud providers like AWS on your behalf, and you can think of
them like stand-ins for what you might do in the AWS console: creating virtual-
machine instances or database clusters, modifying domain-name settings, and
so on. These tools target your cloud provider of choice, and generally run either
Chapter 1: Introducing Pulumi 8
Both types of tools have their rightful place your automation toolbox, and both
operate on a couple of common, fundamental principles:
• The code you write is declarative. Whether you’re writing in plain text, YAML,
or JavaScript, you’re describing what you want your infrastructure to be, not
how the tool should do it. Unlike a shell script that codifies an imperative
set of steps — do this, then this, then this — infrastructure-as-code declares
simply, I want this, and the tool figures out how to effect that reality.
• The tool operates idempotently. Given some declarative code as input, the
tool produces consistent output, regardless of how many times you run
it with that same code. Like a multiply() function that always returns 12
given a 6 and a 2, an IaC tool produces an equally reliable and repeatable
result, free from unexpected side-effects, and changing only what happens
to change in the code from one run to the next.
1. you write some code that declares the end state that you wish to achieve,
2. you run that code with a tool that knows how to interpret and translate it,
and
3. the tool computes what needs to be done, issuing the appropriate com-
mands on the target.
Importantly, though, in order to do its work safely, the tool also needs to know
what already exists. If it didn’t — to return to our dog-walking example —
Chapter 1: Introducing Pulumi 9
it’d stand up two new virtual machines on every run, violating the principle of
idempotency we just established (and racking up lots of AWS charges in the
process). To do things right, IaC tools must incorporate the concept of state,
which you can think of as a point-in-time snapshot of your infrastructure as
of the last time the tool successfully ran. This way, the tool can skip creating
resources that already exist, or change only certain properties of them, doing
only the work that’s necessary to drive the target to the new desired state.
Figure 1.1 shows the parts of a typical IaC workflow and how they all come
together.
Figure 1.1: The high-level components of infrastructure as code. IaC tools like Pulumi evaluate your code,
compare the result with what currently exists, drive your infrastructure to some desired state, recording that
state as the new, now current one.
If you’re new to this practice, it can take some getting used to. But the advantages
are more than worth the effort. Once you start driving your infrastructure with
code, you’ll find it difficult to go back to doing so manually. And for teams and
organizations that need to be able to ship software often and safely, there really
Chapter 1: Introducing Pulumi 10
is no better way.
Still, it can be challenging. With many of these tools, the learning curve can be
steep, especially when you’re trying to learn the tool itself, its unique language,
and the conventions of infrastructure-as-code all at the same time. And since
managing infrastructure has historically fallen under the umbrella of operations,
most of these tools were built by and for operational specialists, so they model
their domains in ways that may make sense to an operator, but leave others
— application developers, programmers from other disciplines, hobbyist coders
— generally lost. Despite how simple it might’ve seemed on the surface, our
little dog-walking app would actually require both classes of IaC tool in order
to be fully automated: a provisioning tool to spin up its virtual machines, and a
configuration management tool run separately afterward to manage the software
installed on both of them. Not so simple after all.
So what do you do? You want to be able to manage your infrastructure as code,
but the tools of the trade are decidedly working against you. Let’s turn now to
Pulumi to see how it can help.
What is Pulumi?
But it’s there that Pulumi begins to diverge from the others in some important
ways:
Chapter 1: Introducing Pulumi 11
• Pulumi ships with an extensive set of language SDKs — npm packages for
Node.js, PyPi for Python, NuGet for .NET, and so on — that model the cloud
in a consistent, rich, and idiomatic way, allowing you to program at high
levels of abstraction.
• By default, Pulumi uses the free Pulumi Service to track the state of your
infrastructure across projects and environments, which other tools tend
leave it to you to manage that on your own. The Service is optional, but
incredibly helpful, so we’ll be using it in this book (and learn more about
it in chapter 3).
These are some of the features that most distinguish Pulumi. We’ll take a first
look at them in a moment, and put them to good use over the course of this book.
Additionally, it can also help to gain a quick understanding of a few of the ideas
behind Pulumi.
Understanding Pulumi
In describing the design goals of the Perl programming language, Larry Wall, its
creator, said something that’s always stuck with me: “Easy things should be easy,
Chapter 1: Introducing Pulumi 12
I haven’t written much Perl, myself. But most of us would probably agree that a
well-designed API of any kind should do exactly that: make it easy to accomplish
the kinds of tasks we do most often, while allowing us to handle the more
complicated ones when we need to.
It’s one of Pulumi’s guiding principles as well, and you can see it in the way
it builds in valuable, often overlooked features like state management, secrets
management (for managing passwords, keys, and the like), and straightforward
configuration — all with the help of the Pulumi service, along with useful APIs
aimed at getting things done.
Let’s combine all we’ve covered up to now and use Pulumi to do something real
— well, semi-real, at least; you’ll build an application of your own in the next
chapter. For now, let’s just walk through a simple Pulumi project together from
start to finish, just to give you a sense of what the end-to-end workflow typically
looks like. The task at hand is ambitious, but achievable: a one-page website
deployed on AWS, purpose-built to deliver the programmer’s all-time favorite
greeting.
Chapter 1: Introducing Pulumi 14
Figure 1.2: A wireframe of the single-page website we’ll build and deploy to AWS with Pulumi.
On AWS, a common way to manage static websites is with the Simple Storage
Service (S3) (https://aws.amazon.com/s3/). With S3, you can store files of any
kind in what’s called a bucket, which you can think of as a uniquely named,
unlimited-capacity folder in the cloud. Since a website (a static one, anyway) is
ultimately just a collection of files in a folder, and S3 offers built-in support for
serving the contents of a bucket as a website, an S3-based website a good fit for
this kind of project.
These steps align with the workflow of pretty much every Pulumi project, as
illustrated in Figure 1.3. Whether you’re building a simple website like this one or
Chapter 1: Introducing Pulumi 15
Figure 1.3: A typical Pulumi workflow: Write some infrastructure code, run Pulumi, and verify the result aligns
with what you expected.
As we go, don’t worry about understanding every last detail; we’ve got the
rest of the book to explore everything in depth. At this point, it’s enough to
understand the broad strokes: what the steps are, what happens at each one,
and how they relate to one another to produce the intended result. Beyond that,
you might also keep an eye out for the ways that Pulumi applies the principles
of infrastructure-as-code that we’ve identified: declarative code, idempotently
applied, and backed by some form of persistent state.
The easiest way to begin a new Pulumi project is with the pulumi command-line
tool (CLI). Since in this book, we’ll mainly be using using TypeScript and AWS,
we’ll use the pulumi new command as follows:
Lots more new-project templates are available for different languages and cloud
providers, and you’ll learn how to write your own templates in part 3, when
Chapter 1: Introducing Pulumi 16
we explore the many ways of packaging and sharing Pulumi projects. After
prompting you for a few details about this one, the command completes, leaving
you with a couple of project configuration files, a package.json file for managing
the project’s dependencies, and an index.ts file containing the TypeScript code
for a minimal Pulumi program that happens to create an S3 bucket.
Now let’s take a look at the contents of that program. Listing 1.1 shows what’s
inside.
Listing 1.1: A Pulumi program that creates a storage bucket on Amazon S3.
If you’ve worked with TypeScript, the first line should look pretty familiar: it just
imports the open-source @pulumi/aws SDK for Node.js, which was installed with
npm when we ran pulumi new. This package contains most of the JavaScript and
TypeScript APIs you’ll use to manage the resources of the AWS cloud, including
the s3 module, which defines the TypeScript Bucket class.
The second line is worth examining a bit more closely, both for what it does
as well as what it doesn’t. It creates an instance of the Bucket class, passing a
name to use for the actual bucket resource, and since we’re in TypeScript, this
is probably what you’d expect. But the program doesn’t appear to do anything
with that instance; there doesn’t seem to be any sort of .create() method being
called anywhere. How does Pulumi know to create an actual S3 bucket?
Chapter 1: Introducing Pulumi 17
We’ll come back to that in a moment. For now, let’s add a bit more code to round
out the program by configuring the bucket to behave like a website. The following
listing shows how that’s done.
Listing 1.2: The same program, extending the S3 bucket to serve a static website.
BucketObject, which we’ll use to contain the content of the home page. Because
we want our visitors to be able to view the page in a browser, we need to tell
AWS to make it publicly accessible, so we provide an acl property (ACL stands
for access-control list) using a TypeScript enum 1 , a handy way to be sure you’re
using a valid value, rather than just a raw string that could be easily mistyped.
For the home page itself, we simply supply a snippet of HTML, but we could
also have written a more elaborate home page in a separate file and imported
it programmatically, using the built-in Node.js FileSystem module — another
example of the benefits of using a real programming language. For example:
Listing 1.3: The same program, using an HTML file read from the local filesystem.
Finally, the last line of the program exports the websiteEndpoint property of the
1 https://www.typescriptlang.org/docs/handbook/enums.html
Chapter 1: Introducing Pulumi 19
bucket instance — the URL of the website — which AWS will compute and expose
to Pulumi once the bucket is created and configured. There’s a good bit of detail
packed into that statement, but for now, it’s enough to note that by exporting
this value, Pulumi will print the value of that property to the terminal, to give us
something to navigate to.
Deploying to AWS
In addition to serving as a helpful way to bootstrap a new project, the Pulumi CLI
is responsible for converting your code into running cloud infrastructure. You’ll
generally divide your time with Pulumi between your editor, writing programs,
and the CLI, running commands like the ones we’ll look at next:
• pulumi preview, which tells you what your program would do, if you were to
deploy it, and
• pulumi update (or pulumi up, for short), which performs an actual deploy-
ment.
When you’re comfortable enough with a program to give it a trial run, you can
open your terminal, change to your project folder, and run pulumi preview. The
output below shows the result for our working example.
Chapter 1: Introducing Pulumi 20
1 $ pulumi preview
2
3 Previewing update (dev):
4 Type Name Plan
5 + pulumi:pulumi:Stack hello-dev create
6 + ├─ aws:s3:Bucket hello-world create
7 + └─ aws:s3:BucketObject index.html create
8
9 Resources:
10 + 3 to create
There are several interesting things to note about this output. First, after evalu-
ating the code, Pulumi’s determined that it needs to create three new resources
— which is interesting, considering we only declared two. The aws:s3:Bucket and
aws:s3:BucketObject look familiar, but where’d the pulumi:pulumi:Stack come
from?
We’ll cover stacks in much more detail in chapter 3, but you can think of them as
logical groupings of cloud resources intended to make it easier for you to manage
your deployments. You can create as many stacks as you like for a given project,
name them however you like, and configure them independently of one another.
By default, Pulumi offers to create a dev stack for every new project; we accepted
that default when we ran pulumi new.
It looks like this hypothetical dev stack would contain two actual cloud resources
after all, which sounds about right. Now let’s see what happens when we run the
update for real.
Chapter 1: Introducing Pulumi 21
1 $ pulumi up
2
3 Updating (dev):
4 Type Name Status
5 + pulumi:pulumi:Stack hello-dev created
6 + ├─ aws:s3:Bucket hello-world created
7 + └─ aws:s3:BucketObject index.html created
8
9 Outputs:
10 url: "hello-world-ae6198e.s3-website-us-west-2.amazonaws.com"
11
12 Resources:
13 + 3 created
14
15 Duration: 18s
16
17 Permalink: https://app.pulumi.com/cnunciato/hello/dev/updates/1
The output suggests Pulumi did what was expected: All three resources have now
been created, and the export statement we declared in the program has produced
a url property listed under Outputs. Navigating to that URL reveals the final
product, in all its minimalist glory.
Chapter 1: Introducing Pulumi 22
Figure 1.4: The finished product, now deployed as a static website on AWS.
You’ll find the source code for this example, along with all others con-
tained in this book, on GitHub at https://github.com/thepulumibook.
Now let’s conclude this excursion by following the Permalink to the Pulumi
Console. The Console is the web interface for the Pulumi Service, which Pulumi
uses by default to manage the state of your infrastructure, along with all of your
projects, stacks, and integrations with third-party services like GitHub (which
you’ll learn more about in part 3, when we explore continuous integration and
delivery). Let’s do that now.
Our project has a permanent home in the Pulumi Console. There, you’ll see a
history of all of the changes made to your each of your Pulumi stacks, along with
the resources that belong to each one. Figure 1.5 shows the Resources tab of the
hello project’s dev stack, which lists the bucket and bucket object, each with a
link to their respective locations in the AWS Management Console.
Chapter 1: Introducing Pulumi 23
Figure 1.5: The Pulumi Console, a free service that helps you manage your Pulumi projects and stacks.
There, you can inspect the properties of the bucket, as shown in Figure 1.6.
Chapter 1: Introducing Pulumi 24
Figure 1.6: The bucket and bucket object, as seen in the AWS Management Console.
We began with the pulumi new command, which generated a Pulumi project for us,
along with a complete, ready-to-run TypeScript program defining an S3 bucket.
We added a few lines of code to turn that bucket into a website, ran pulumi preview
to get a glimpse of the cloud resources the program would create, and ran pulumi
up to create them. And finally, we verified the result by viewing the website
in a browser, the project and stack in the Pulumi Console, and the resources
themselves on AWS. If we wanted, we could make a change to the homepage, run
pulumi up, and have that change deployed instantly, or even delete the website
Chapter 1: Introducing Pulumi 25
entirely with another command, pulumi destroy, which you’ll use to tidy up after
the project you build in the next chapter.
You also learned that by default, the Pulumi CLI uses the free Pulumi Service to
manage the state of your infrastructure over time, and that the Pulumi Console
offers a convenient way to keep track of your projects, stacks, and cloud resources
all in one place. You’ll learn much more about the Service and Console in the
chapters ahead.
Let’s expand our working model now into a more detailed one to carry with you as
you move forward. Again, don’t worry if you don’t understand everything here;
we’ll return to this model repeatedly throughout the book. But you’ve learned
enough at this point that it’d be good to get a more complete sense of how Pulumi
really works.
Figure 1.7 zooms in on the Pulumi CLI to reveal a couple of new but important
parts: the language host, which actually runs the code that you write, and the
resource provider, which handles communicating with the cloud service to create,
read, update, or delete the resources you define in your Pulumi programs.
Chapter 1: Introducing Pulumi 26
Figure 1.7: A closer look at the Pulumi CLI. Pulumi passes your code to a language host (such as Node.js), waits to
be notified of resource registrations, assembles a model of your desired state, and calls on the resource provider
to produce that state by communicating directly with cloud services like AWS.
Earlier I mentioned we’d come back to the part about how Pulumi knew to create
the S3 bucket and homepage, given that all we’d done was instantiate a couple of
objects. That’s where the language host comes in. When we ran pulumi preview
and later pulumi up, the Pulumi CLI determined that since our chosen language
was TypeScript, our program code should be run with Node.js. (If we’d written
a program in Python, it would’ve used Python; if C#, .NET Core, and so on.) So
Pulumi launched Node implicitly, passed it our code, and waited to be notified of
resource declarations.
Our calls to construct new Bucket() and new BucketObject() instances were exactly
that — declarations to Pulumi of a desire to have these two resources exist in our
infrastructure stack. Importantly, the resources weren’t actually created on AWS
in that moment; rather, their details were simply captured by Pulumi, collected,
and compared with our existing state. Since that state was empty (as new projects
are), Pulumi computed that these resources should be created, so it assembled a
list of operations to perform — create a new bucket, configure the bucket as website,
create a new file in that bucket — and passed that list to the resource provider,
Chapter 1: Introducing Pulumi 27
which translated them into API requests to perform on the AWS service itself.
When the work of the resource provider was complete and our resources created,
Pulumi updated our stack’s state accordingly, saving it back to the Pulumi Service
for use on the next run.
Every Pulumi project follows the very same workflow, from simple websites
like this one, to serverless web applications, to the most complex cloud-native
deployments involving hundreds or thousands of resources: one tool, one work-
flow, and one language, start to finish. And it’s only a short hop from here to the
Git-driven workflow I mentioned at the beginning of the chapter — which, as it
happens, you’ll learn how to do in part 3.
Let’s round out this chapter by highlighting a few of Pulumi’s unique strengths.
We all come to the cloud with different backgrounds and experiences. I men-
tioned I’m a web developer; you might be, too — or you might be a data scientist
looking to move a computational workload into AWS, or a release engineer
working to improve the way your company ships software. Whoever you are,
if you’re reading this book, there’s a pretty good chance you aren’t an expert
in cloud operations, and an equally good chance you’re at least moderately
comfortable with at least one high-level programming language, whatever that
language happens to be.
Pulumi was built with this in mind. Rather than expect you to learn a new
discipline, or vendor- or tool-specific language, it lets you start with a language
Chapter 1: Introducing Pulumi 28
you already know well, and go from there. In practice, that means you can
generally hit the ground running, applying the skills you already have to what
might well be a totally new domain for you. (As it was for me.)
It also means being able to bring all of the benefits of your chosen language
and its ecosystem along for the ride. As you’ve seen, a Pulumi program is just
a regular program — a Node.js script, a Go program with a main entrypoint —
so you can use whatever organizational constructs, language features, or third-
party libraries you like with Pulumi, too.
And if you’re a fan, as I am, of tools like Visual Studio Code, you’ve probably come
to appreciate features like type checking, IntelliSense, and head’s up documen-
tation that make it easier to explore and use APIs you may still be learning. Figure
1.8 shows what it’s like to develop with the Pulumi SDK for Node.js, where code
hinting and inline documentation help to keep you productive and on the happy
path.
Figure 1.8: Deep support for programming languages enables syntax highlighting, code completion, inline
documentation, automated refactoring, and more, with popular tools like Visual Studio Code.
Chapter 1: Introducing Pulumi 29
As a developer, I’m used to working at a fairly high level. The languages I use
most often are built to help me work productively, and at a level of abstraction
that allows me to get things done. TypeScript, for instance, is a great fit for web
development work. C, on the other hand, would not be — it’s too low-level, too
“close to the metal”. If building web applications meant having to learn and use
C every day, there’d be a lot fewer web applications in the world, and a lot fewer
web developers, too. It’d just be too difficult for most people to bother with.
And yet that’s what a lot of infrastructure tools seem to expect from us — to
descend from our high-level cruising altitudes back down to sea level just to
manage some infrastructure.
When you want a bucket, you can ask for a bucket — but when you want a
serverless REST API, you can also just ask for a serverless REST API, and the
Pulumi SDK will likely be there to help you. That that a REST API might consist of
a dozen or more cloud resources — a network, gateway, multiple cloud functions
and access policies, etc. — is an implementation detail that Pulumi knows you
probably don’t care all that much about, so long as it works, is appropriately
secure, and you can customize and extend it when you need to. Easy things are
easy, and hard things are possible.
Chapter 1: Introducing Pulumi 30
A lot of developer-focused cloud tools do a few things really well, like help you
build and deploy static websites and distribute them globally, or make it easy
to add serverless API endpoints for those websites with a little configuration.
Many of these tools are truly great at what they do — but when you find yourself
hitting the edges of what they’re capable of, like when it’s time to add a relational
database, or a horizontally scalable API service, you usually have figure those
things out on your own, which often means having to go back to clicking buttons
in a dashboard, or using some other tool to set those additional components up
for you.
The Pulumi SDK gives you a rich set of language-specific APIs that aim to model
the whole cloud, consistently and idiomatically — all major clouds, by the way;
not just AWS — which means you can write programs that create static websites,
serverless APIs, database clusters, or containerized services as easily as you can
a single S3 bucket — and even wire them all together within the scope of a single
program.
In this book, we’re focused mainly on learning Pulumi by building small appli-
cations, but it’s important to know that Pulumi is made to handle the needs of
large organizations as well, where responsibilities are often split between teams
of developers and operators, and where operators are charged with the task of
building secure, reliable cloud platforms of their own that can handle constant
change and unbounded scale.
for example, is not only a flexible and productive language with a massive com-
munity and ecosystem; it also lends itself well to modern software-engineering
practices like linting, testing, debugging, and refactoring, among others — prac-
tices that help us keep our code under control as our systems grow larger and
ever more complicated. Nothing is worse than having to work in a codebase
that’s huge, brittle, and hard to understand. With Pulumi, you’ll manage your
infrastructure as software, refactoring as you go to keep things clean and under
control.
Programs must be written for people to read, and only incidentally for
machines to execute.
— Harold Abelson and Gerald Jay Sussman, Preface to the Second Edition,
Structure and Interpretation of Computer Programs
You’ve learned quite a bit about Pulumi in this chapter, and I hope you’re excited
to keep learning more. Now would be a good time to take a break with your own
beverage of choice before heading into chapter 2, where you’ll build your first
cloud-native application with Pulumi.
Chapter 1: Introducing Pulumi 32
Summary
• With Pulumi, you write programs that declare cloud resources as collections
of objects, and Pulumi translates those programs into running cloud soft-
ware.
• With the Pulumi CLI, you can generate new projects, preview infrastructure
changes before you make them, and modify your infrastructure safely and
idempotently.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Enter serverless
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 2: Your first Pulumi program 34
Node.js
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 2: Your first Pulumi program 35
index.ts
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
tsconfig.json
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 2: Your first Pulumi program 36
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 2: Your first Pulumi program 37
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Tidying up
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Summary
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 3: Projects and stacks
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Sketching it out
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 3: Projects and stacks 39
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 3: Projects and stacks 40
Wiring up notifications
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Posting to Slack
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Taking stock
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 3: Projects and stacks 41
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Tidying up
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Summary
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 4: Configuration and secrets
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
A quick recap
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 4: Configuration and secrets 43
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 4: Configuration and secrets 44
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Tidying Up
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Chapter 4: Configuration and secrets 45
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Deleting stacks
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Summary
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.
Appendix A: Setting Things Up
This content is not available in the sample book. The book can be purchased on
Leanpub at http://leanpub.com/pulumi.