Advanced Pulumi

Session Overview

  • Pulumi README
  • Importing resources across Stacks
  • Embedding Outputs in text (policies)
  • Working with JSON
  • Working with non-pulumi resources
  • Control Structures
  • Multiple Account Stacks

Pulumi Stack README

Stack README Useful for additional level of documentation.

  • Markdown Document
  • Dynamically updates with Stack Outputs
  • Exported alongside stack
  • Shows up in Pulumi Dashboard

Pulumi Stack README

  1. Add Pulumi.README.md to 02-building directory.


# Lambda Parsing Project

More information about your project and resources...

## Key components:

Lambda Function: ${outputs.pw-lambda-user-lambda}
ECR: ${outputs.ecr}


  1. Add the following to end of launch_stack function in launch_stack.py:
with open('./Pulumi.README.md') as f:
    pulumi.export('readme', f.read())
  • Pulumi README
  • Importing resources across Stacks
  • Embedding Outputs in text (policies)
  • Working with JSON
  • Working with non-pulumi resources
  • Control Structures
  • Multiple Account Stacks

Importing Resources Across Stacks

Information about resources that is exported in a stack is available programmatically via the Pulumi CLI and Pulumi SDKs.


Pulumi CLI

pulumi stack output --stack ncics/pulumi-workshop/workshop-infrastructure

Pulumi Python SDK

import pulumi

stack_ref = pulumi.StackReference("ncics/pulumi-workshop/workshop-infrastructure")

dsw_cloud9_arn = stack_ref.get_output("dwillett-arn")

Let’s Try It!

  1. On Cloud9, navigate to the GitLab repo and the 03-cross-stack directory.

  2. Run the environment setup, activate the environment, and run the query_stack.py file.


What happens?

Embedding Outputs in Text

Outputs represent values that are not initially known but will become available once the infrastructure resource has completed provisioning.


  • Special Type in Pulumi
  • Essentially a promise.
  • Asynchronous
  • Accessed through Apply and All

Embedding Outputs in Text

Critically important for custom policies and anything JSON.


Let’s set up an s3 bucket for event-driven notifications.


See 04-outputs directory.

Session Overview

  • Pulumi README
  • Importing resources across Stacks
  • Embedding Outputs in text (policies)
  • Working with JSON
  • Working with non-pulumi resources
  • Control Structures
  • Multiple Account Stacks

Non-Pulumi Resources

  • Convert Terraform, OpenTofu

  • Leverage CloudFormation

  • Import existing resources

    • Equally good for managing and for finding configuration

Importing Resources

  • Can be done via the CLI or via Python

CLI

  1. Run cd ~

  2. Make a new directory mkdir pulumi-import and move to it cd pulumi-import.

  3. Run pulumi new.

  4. Run pulumi import aws:ec2/instance:Instance <name> <id>


What did you get?

Session Overview

  • Pulumi README
  • Importing resources across Stacks
  • Embedding Outputs in text (policies)
  • Working with JSON
  • Working with non-pulumi resources
  • Control Structures
  • Multiple Account Stacks

Leveraging Pulumi

Using Control Structures and Multiple Accounts in a Single Stack

Accelerating Pulumi

Pulumi AI

Your Challenge

Find two friends. For each friend, create an sns topic they can subscribe to. Then create a lambda with a function url that posts a message to this SNS topic depending on which name it receives. (You can work together on this… and please leverage AI tools.)

Recap

Recap:


It’s a Pulumi Party!


At this point:

  • You have Launched, Updated, and Destroyed many stacks.
  • You have leverage the Pulumi Automation API for an extra level of automation.
  • You have shared resources across stacks and imported non-pulumi resources.
  • You have used control structures to scale infrastructure.

Keep Learning!