1.6 Creating a Second Stack

It is easy to create multiple instances of the same project. This is called a stack and is handy for multiple development or test environments, staging versus production, and scaling a given infrastructure across many regions.

Step 1 — Create and Configure a New Stack

Create a new stack:

pulumi stack init prod

Next, configure its two required variables:

pulumi config set aws:region us-west-2
pulumi config set iac-workshop:siteDir wwwprod

If you are ever curious to see the list of stacks for your current project, run this command:

pulumi stack ls

It will print all stacks for this project that are available to you:

NAME   LAST UPDATE     RESOURCE COUNT  URL
dev    30 minutes ago  5               https://app.pulumi.com/workshops/iac-workshop/dev
prod*  3 minutes ago   0               https://app.pulumi.com/workshops/iac-workshop/prod

Step 2 — Populate the New Site Directory

It would have been possible to use the existing www directory for the siteDir. In this example, you will use a different wwwprod directory, to demonstrate the value of having configurability.

Create this new directory:

mkdir wwwprod

Add a new index.html file to it:

<html>
    <body>
        <h1>Hello Pulumi</h1>
        <p>(in production!)</p>
    </body>
</html>

Step 3 — Deploy the New Stack

Now deploy all of the changes:

pulumi up

This will create an entirely new set of resources from scratch, unrelated to the existing dev stack’s resources.

Updating (prod):

     Type                    Name               Status
 +   pulumi:pulumi:Stack     iac-workshop-prod  created
 +   ├─ aws:s3:Bucket        my-bucket          created
 +   └─ aws:s3:BucketObject  index.html         created

Outputs:
    bucketEndpoint: "http://my-bucket-5692022.s3-website-us-west-2.amazonaws.com"
    bucketName    : "my-bucket-5692022"

Resources:
    + 3 created

Duration: 28s

Permalink: https://app.pulumi.com/workshops/iac-workshop/prod/updates/1

Now fetch your new website:

curl $(pulumi stack output bucketEndpoint)

Notice that it’s the new production version of your content:

<html>
    <body>
        <h1>Hello Pulumi</h1>
        <p>(in production!)</p>
    </body>
</html>