Skip to main content

StackReference example

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-stackreference
cd pulumi-examples/aws-ts-stackreference

This example creates a “team” EC2 Instance with tags set from upstream “company” and “department” stacks via StackReference.

/**
* company
* └─ department
* └─ team
*/

This directory contains three Pulumi projects that must be deployed in order:

  • company/ — exports the company name.
  • department/ — exports the department name.
  • team/ — creates an EC2 instance tagged with values read from the company and department stacks.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js

Deploying the example#

  1. Change to the company directory and install dependencies:

    Terminal window
    cd company
    npm install
  2. Create a new stack:

    Terminal window
    pulumi stack init dev
  3. Set the required configuration variables:

    Terminal window
    pulumi config set companyName 'ACME Widget Company'
  4. Deploy the stack with pulumi up:

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Status
    + pulumi:pulumi:Stack aws-ts-stackreference-company-dev created
    Outputs:
    companyName: "ACME Widget Company"
    Resources:
    + 1 created
    Duration: 1s
  5. Change to the department directory and install dependencies:

    Terminal window
    cd ../department
    npm install
  6. Create a new stack:

    Terminal window
    pulumi stack init dev
  7. Set the required configuration variables:

    Terminal window
    pulumi config set departmentName 'E-Commerce'
  8. Deploy the stack with pulumi up:

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Status
    + pulumi:pulumi:Stack aws-ts-stackreference-department-dev created
    Outputs:
    departmentName: "E-Commerce"
    Resources:
    + 1 created
    Duration: 1s
  9. Change to the team directory and install dependencies:

    Terminal window
    cd ../team
    npm install
  10. Create a new stack:

    Terminal window
    pulumi stack init dev
  11. Set the required configuration variables, replacing YOUR_ORG with the name of your Pulumi organization:

    Terminal window
    pulumi config set companyStack YOUR_ORG/aws-ts-stackreference-company/dev
    pulumi config set departmentStack YOUR_ORG/aws-ts-stackreference-department/dev
    pulumi config set teamName 'Frontend Dev'
    pulumi config set aws:region us-west-2 # any valid AWS region works
  12. Deploy the stack with pulumi up:

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Status
    + pulumi:pulumi:Stack aws-ts-stackreference-team-dev created
    >- ├─ pulumi:pulumi:StackReference clstokes/aws-ts-stackreference-company/dev read
    >- ├─ pulumi:pulumi:StackReference clstokes/aws-ts-stackreference-department/dev read
    + └─ aws:ec2:Instance tagged created
    Outputs:
    instanceId : "i-0a9ede9c446503903"
    instanceTags: {
    Managed By: "Pulumi"
    company : "ACME Widget Company"
    department: "E-Commerce"
    team : "Frontend Dev"
    }
    Resources:
    + 2 created
    Duration: 28s

Cleaning up#

Once you are done, destroy the resources and remove the stack. Repeat this in each of the company, department, and team directories that you ran pulumi up within:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.