Mantra Networking Mantra Networking

Pulumi: Pulumi CLI

Pulumi: Pulumi CLI
Created By: Lauren R. Garcia

Table of Contents

  • Overview
  • Common Pulumi CLI Commands
  • Additional Useful CLI Commands
  • Sample Pulumi Program (TypeScript & Python)
  • Getting Started Workflow
  • Conclusion

Pulumi CLI Overview

What is the Pulumi CLI?

The Pulumi Command-Line Interface (CLI) is the core tool you use to define, deploy, and manage cloud infrastructure using familiar programming languages. Unlike traditional Infrastructure as Code (IaC) tools that require domain-specific languages or templating, Pulumi leverages real programming languages like Python, TypeScript, Go, and C# to express infrastructure intent. The CLI acts as the gateway between your code and the orchestration of resources within your chosen cloud provider (AWS, Azure, GCP, and more).

Why You Need to Know About Pulumi CLI

  • Modern Automation: The Pulumi CLI brings software engineering best practices—like version control, testing, and modularization—to infrastructure management.
  • Increased Productivity: Using real languages means you can harness features like loops, conditionals, abstractions, and package management, making your infrastructure code scalable and reusable.
  • Multi-Cloud & Hybrid-Cloud Ready: Pulumi’s CLI can orchestrate resources across multiple clouds or even on-premises setups from a single codebase and workflow.
  • DevOps Alignment: The CLI seamlessly fits into CI/CD pipelines, enabling automated deployments and infrastructure updates without manual intervention.

How the Pulumi CLI Works

  1. Project Initialization: You start by scaffold a new project using the CLI, choosing your stack (environment) and preferred programming language.
  2. Program Authoring: Define the desired state of your infrastructure—such as virtual machines, storage buckets, networks—using code. Pulumi’s SDK for your chosen language provides all the building blocks.
  3. Preview: With a single command, the CLI generates a human-readable preview map, showing what will be created, updated, or deleted.
  4. Deployment: Running the deployment command applies your code’s intent to the cloud, safely provisioning resources. Any resource state is tracked automatically by Pulumi.
  5. Management: The CLI allows stack management (e.g., different environments like dev/staging/prod), configuration handling, and state synchronization to ensure your code and infrastructure remain aligned.
  6. Destruction: Resources can be safely destroyed when no longer needed, helping control costs and supporting infrastructure lifecycle best practices.

Pulumi CLI stands out by unifying infrastructure and application code, which means you can build richer, safer, and more automated cloud solutions—using the same languages and tools you use daily for application development. This promotes agility, scales with your team’s expertise, and accelerates modern network automation and provisioning.

Common Pulumi CLI Commands

The Pulumi CLI offers a powerful, flexible set of commands to build, deploy, and manage your cloud infrastructure as code. Below is a quick reference to help you navigate the most frequently used commands in your workflow.

Command Description
pulumi new Create a new Pulumi project using a template, and select your preferred cloud and language.
pulumi stack Manage isolated environments (“stacks”) for your project, like dev, staging, or prod.
pulumi config Configure and manage stack-specific variables—API keys, regions, secrets, etc.
pulumi up Preview and deploy changes to your infrastructure. Applies your desired state.
pulumi preview Show what will change before performing any updates. Ideal for reviews.
pulumi destroy Tear down and delete all resources for the current stack—be careful!

Step-by-Step: Typical Workflow

  1. Initialize your project with pulumi new.
  2. Create or select a stack using pulumi stack.
  3. Set configuration values with pulumi config set <key> <value> as needed.
  4. Preview infrastructure changes using pulumi preview.
  5. Deploy changes with pulumi up.
  6. Destroy resources when no longer needed using pulumi destroy.

Mastering these commands lets you automate cloud deployments with confidence and efficiency.

Additional Useful CLI Commands

Beyond the core Pulumi commands, the CLI provides several additional tools to streamline workflows, troubleshoot deployments, manage environments, and customize project behavior. Below is a list of helpful commands every Pulumi user should be familiar with.

Command Description
pulumi about Displays detailed version and environment information about the Pulumi CLI.
pulumi cancel Cancels a currently executing update operation if it appears stuck or unresponsive.
pulumi console Opens the Pulumi Console in your browser for visual management and insights.
pulumi logs Streams deployment logs for active resources in real-time—ideal for debugging live updates.
pulumi refresh Fetches and reconciles the current state of real-world infrastructure with the Pulumi state file.
pulumi plugin Manages Pulumi language and provider plugins (install, remove, list).
pulumi gen-completion Generates shell autocompletion scripts for Bash, Zsh, or Fish to boost CLI productivity.
pulumi whoami Displays your currently authenticated Pulumi user account.

Step-by-Step: Useful Scenarios

  1. Check environment setup with pulumi about before troubleshooting version issues.
  2. Cancel a stuck deployment using pulumi cancel when an update fails to complete.
  3. Get real-time activity logs via pulumi logs to monitor infrastructure boot time behavior.
  4. Force state resync with pulumi refresh if manual cloud changes interfere with Pulumi's state.
  5. Manage provider updates using pulumi plugin upgrade after enabling a new cloud service.
  6. Enable CLI efficiency by installing shell completions using pulumi gen-completion.

These commands provide flexibility and tooling to support large-scale automation, debugging, and administrative operations in modern infrastructure pipelines.

Sample Pulumi Program (TypeScript & Python)

To better understand how Pulumi works in practice, here’s a step-by-step example of a simple infrastructure deployment: hosting a static website on AWS S3. We'll provide both TypeScript and Python versions of the same Pulumi program.

Objective:

  • Create an S3 bucket configured as a static website
  • Upload an index.html file
  • Export the website’s public endpoint

TypeScript Example:


import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("website", {
    website: {
        indexDocument: "index.html",
    },
});

new aws.s3.BucketObject("index", {
    bucket: bucket,
    content: "<!DOCTYPE html><html><body><h1>Hello from Pulumi!</h1></body></html>",
    key: "index.html",
    contentType: "text/html",
});

export const websiteUrl = bucket.websiteEndpoint;


Python Example:


import pulumi
import pulumi_aws as aws

bucket = aws.s3.Bucket("website",
    website=aws.s3.BucketWebsiteArgs(
        index_document="index.html"
    )
)

aws.s3.BucketObject("index",
    bucket=bucket.id,
    content="<!DOCTYPE html><html><body><h1>Hello from Pulumi!</h1></body></html>",
    key="index.html",
    content_type="text/html"
)

pulumi.export("website_url", bucket.website_endpoint)


Step-by-Step Deployment

  1. Initialize a new project using pulumi new aws-typescript or pulumi new aws-python.
  2. Replace the program in index.ts or __main__.py with one of the examples above.
  3. Run pulumi up to preview and deploy your AWS S3 website infrastructure.
  4. Visit the exported websiteUrl in your browser to view the hosted HTML page.

Using Pulumi with general-purpose programming languages like TypeScript and Python makes it easy to express cloud infrastructure as code with loops, conditionals, and modular reuse.

Getting Started Workflow

The Pulumi CLI makes it simple to start managing infrastructure from the command line using familiar programming languages. This step-by-step guide outlines a typical workflow you can follow when getting started with Pulumi in a new project.

Step-by-Step Setup Process:

  1. Install Pulumi CLI:
    Download and install the Pulumi CLI for your platform. Once installed, verify by running:
    pulumi version
  2. Log in to Pulumi:
    Authenticate with the Pulumi service (or your preferred backend) using:
    pulumi login
  3. Start a new project:
    Use the pulumi new command to scaffold a new project:
    pulumi new aws-python
    This initializes a new directory with boilerplate files for your selected cloud and language.
  4. Customize your infrastructure code:
    Open the project files and modify the code within __main__.py or index.ts to define the desired infrastructure.
  5. Initialize or select a stack:
    Stacks allow you to manage different deployment environments (e.g., dev, staging, prod). Create or select a stack using:
    pulumi stack init dev or pulumi stack select dev
  6. Configure stack settings:
    Use pulumi config to set environment-specific values:
    pulumi config set aws:region us-west-2
  7. Review deployment changes:
    Before making changes, preview your plan:
    pulumi preview
  8. Deploy your infrastructure:
    Apply the infrastructure as code using:
    pulumi up
    Confirm the changes in the preview and let Pulumi perform the update.
  9. Destroy resources when finished:
    If you want to tear everything down, run:
    pulumi destroy

This workflow is at the core of Pulumi’s simplicity: define your infrastructure in code, preview the result, and deploy with confidence.

Conclusion

Throughout this blog post, we’ve explored the essentials of the Pulumi CLI — a powerful tool for cloud infrastructure automation that blends the familiarity of programming languages with the flexibility of modern DevOps practices.

Key Takeaways:

  • Pulumi CLI Basics: We broke down the core commands like pulumi newpulumi up, and pulumi destroy, which are fundamental to any Pulumi workflow.
  • Advanced CLI Commands: You now know how to enhance productivity using commands like pulumi logspulumi refresh, and pulumi gen-completion.
  • Hands-On Programming Examples: Whether you prefer TypeScript or Python, we walked through real-world examples of deploying a static website to AWS S3 using Pulumi.
  • Step-by-Step Workflow: From installing the CLI to configuring stacks and deploying infrastructure, we outlined a repeatable, beginner-friendly workflow to get your projects off the ground.

Pulumi stands out by allowing infrastructure to be written in modern programming languages — enabling loops, conditionals, abstractions, and better modularity. This makes it an incredibly scalable option for teams looking to modernize and automate their cloud infrastructure using existing engineering skillsets.

Thanks for reading — you’re now fully equipped to dive into Pulumi with confidence! Whether you're managing a couple of cloud resources or orchestrating multi-tier architectures across environments, the Pulumi CLI makes it all approachable and version-controllable.

🚀 Happy provisioning, and may your cloud deployments always pulumi up successfully!