Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

StackReference example

This 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
   └─ team

Prerequisites

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Python

Deploying the example

Part 1: The company stack

  1. Change to the company directory and install dependencies:

    cd company
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  2. Create a new stack:

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

    pulumi config set companyName 'ACME Widget Company'
  4. Deploy the stack:

    pulumi up
    Updating (dev):
    
        Type                 Name                               Status
    +   pulumi:pulumi:Stack  aws-py-stackreference-company-dev  created
    
    Outputs:
        companyName: "ACME Widget Company"
    
    Resources:
        + 1 created
    

Part 2: The department stack

  1. Change to the department directory and install dependencies:

    cd ../department
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  2. Create a new stack:

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

    pulumi config set departmentName 'E-Commerce'
  4. Deploy the stack:

    pulumi up
    Updating (dev):
    
        Type                 Name                                  Status
    +   pulumi:pulumi:Stack  aws-py-stackreference-department-dev  created
    
    Outputs:
        departmentName: "E-Commerce"
    
    Resources:
        + 1 created
    

Part 3: The team stack

  1. Change to the team directory and install dependencies:

    cd ../team
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  2. Create a new stack:

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

    pulumi config set companyStack YOUR_ORG/aws-py-stackreference-company/dev
    pulumi config set departmentStack YOUR_ORG/aws-py-stackreference-department/dev
    pulumi config set teamName 'Frontend Dev'
    pulumi config set aws:region us-west-2
  4. Deploy the stack:

    pulumi up
    Updating (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                                         created
    
    Outputs:
        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 destroy
pulumi stack rm