StackReference example
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-py-stackreferencecd pulumi-examples/aws-py-stackreferenceThis example creates a “team” EC2 Instance with tags set from upstream “company” and “department” stacks via StackReference.
This directory contains three Pulumi projects that are deployed in sequence:
- company/ — creates a “company” stack that exports a company name.
- department/ — creates a “department” stack that exports a department name.
- team/ — creates an EC2 instance tagged with values read from the company and department stacks.
company└─ department └─ teamPrerequisites#
Deploying the example#
Part 1: The company stack#
-
Change to the
companydirectory and install dependencies:Terminal window cd companypython3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Create a new stack:
Terminal window pulumi stack init dev -
Set the required configuration variables:
Terminal window pulumi config set companyName 'ACME Widget Company' -
Deploy the stack:
Terminal window pulumi upUpdating (dev):Type Name Status+ pulumi:pulumi:Stack aws-py-stackreference-company-dev createdOutputs:companyName: "ACME Widget Company"Resources:+ 1 created
Part 2: The department stack#
-
Change to the
departmentdirectory and install dependencies:Terminal window cd ../departmentpython3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Create a new stack:
Terminal window pulumi stack init dev -
Set the required configuration variables:
Terminal window pulumi config set departmentName 'E-Commerce' -
Deploy the stack:
Terminal window pulumi upUpdating (dev):Type Name Status+ pulumi:pulumi:Stack aws-py-stackreference-department-dev createdOutputs:departmentName: "E-Commerce"Resources:+ 1 created
Part 3: The team stack#
-
Change to the
teamdirectory and install dependencies:Terminal window cd ../teampython3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Create a new stack:
Terminal window pulumi stack init dev -
Set the required configuration variables, replacing
YOUR_ORGwith the name of your Pulumi organization:Terminal window pulumi config set companyStack YOUR_ORG/aws-py-stackreference-company/devpulumi config set departmentStack YOUR_ORG/aws-py-stackreference-department/devpulumi config set teamName 'Frontend Dev'pulumi config set aws:region us-west-2 -
Deploy the stack:
Terminal window pulumi upUpdating (dev):Type Name Status+ pulumi:pulumi:Stack aws-py-stackreference-team-dev created>- ├─ pulumi:pulumi:StackReference clstokes/aws-py-stackreference-company/dev read>- ├─ pulumi:pulumi:StackReference clstokes/aws-py-stackreference-department/dev read+ └─ aws:ec2:Instance tagged createdOutputs:instanceId : "i-0a9ede9c446503903"instanceTags: {Managed By: "Pulumi"company : "ACME Widget Company"department: "E-Commerce"team : "Frontend Dev"}Resources:+ 2 created
Cleaning up#
Once you’re finished experimenting, destroy your resources and remove your stacks. Repeat this in each of the company, department, and team directories that you ran pulumi up within:
pulumi destroypulumi stack rm