Introduction to Pulumi: A Modern Infrastructure as Code Tool – part 1

Pulumi is an open-source infrastructure as code (IaC) tool that enables developers to define, deploy, and manage cloud resources using familiar programming languages such as Python, TypeScript, JavaScript, Go, and C#. Unlike traditional IaC tools such as Terraform, which use domain-specific languages (DSL), Pulumi leverages general-purpose languages, providing more flexibility and enabling developers to use existing tooling, libraries, and frameworks.

In this article, we’ll explore the basics of Pulumi and compare how to create and manage a simple cloud resource (an S3 bucket in AWS, a Cloud Storage bucket in Google Cloud, and a Blob Storage container in Azure) across three major cloud providers using Python. For a deeper dive into strategising your infrastructure across diverse environments, explore our insights on Multi-Cloud and Hybrid Cloud Deployments.

 

Pulumi Infrastructure as Code on laptop screen

Getting Started with Pulumi for Infrastructure as Code

To get started with Pulumi, you need to install the Pulumi CLI and set up your environment. Here’s a brief guide to get you up and running:

  • Install Pulumi CLI:bashCopy code curl -fsSL https://get.pulumi.com | sh
  • Log in to Pulumi:bashCopy code pulumi login
  • Create a new Pulumi project:bashCopy code pulumi new python
  • Pulumi IaC: Example of Creating a Storage Bucket Across Clouds

    AWS S3 Bucket with Pulumi IaC

    First, install the necessary Pulumi AWS package:

    pip install pulumi pulumi-aws

    Then, create a new Python file (__main__.py) with the following content:

    import pulumi
    import pulumi_aws as aws
    
    # Create an S3 bucket
    bucket = aws.s3.Bucket('my-bucket', acl='private')
    
    # Export the bucket name
    pulumi.export('bucket_name', bucket.id)

    Deploy the stack:

    pulumi up

    Google Cloud Storage Bucket with Pulumi

    For Google Cloud, install the Pulumi GCP package:

    pip install pulumi pulumi-gcp

    Create a new Python file (__main__.py) with the following content:

    import pulumi
    import pulumi_gcp as gcp
    
    # Create a Cloud Storage bucket
    bucket = gcp.storage.Bucket('my-bucket', location='US')
    
    # Export the bucket name
    pulumi.export('bucket_name', bucket.name)

    Deploy the stack:

    pulumi up

    Azure Blob Storage Container with Pulumi IaC

    For Azure, install the Pulumi Azure package:

    pip install pulumi pulumi-azure

    Create a new Python file (__main__.py) with the following content:

    import pulumi
    import pulumi_azure as azure
    
    # Create an Azure Resource Group
    resource_group = azure.core.ResourceGroup('my-resource-group')
    
    # Create a Storage Account
    account = azure.storage.Account('mystorageaccount',
                                    resource_group_name=resource_group.name,
                                    account_replication_type='LRS',
                                    account_tier='Standard')
    
    # Create a Blob Storage container
    container = azure.storage.Container('my-container',
                                        storage_account_name=account.name,
                                        container_access_type='private')
    
    # Export the container name
    pulumi.export('container_name', container.name)

    Deploy the stack:

    pulumi up

    Comparing Pulumi Infrastructure as Code for Multi-Cloud

    Here’s a comparison of the code snippets for creating a storage bucket across AWS, Google Cloud, and Azure:

    AWS Pulumi Code

    Uses the pulumi_aws package to create an S3 bucket:

    import pulumi 
    import pulumi_aws as aws
    
    bucket = aws.s3.Bucket('my-bucket', acl='private') 
    pulumi.export('bucket_name', bucket.id)

    Google Cloud Pulumi Code

    Uses the pulumi_gcp package to create a Cloud Storage bucket:

    import pulumi 
    import pulumi_gcp as gcp 
    
    bucket = gcp.storage.Bucket('my-bucket', location='US') 
    pulumi.export('bucket_name', bucket.name)

    Azure Pulumi Code

    Uses the pulumi_azure package to create a Blob Storage container:

    import pulumi 
    import pulumi_azure as azure 
    
    resource_group = azure.core.ResourceGroup('my-resource-group') 
    account = azure.storage.Account('mystorageaccount', 
                                    resource_group_name=resource_group.name,
                                    account_replication_type='LRS', 
                                    account_tier='Standard') 
    
    container = azure.storage.Container('my-container', 
                                        storage_account_name=account.name,
                                        container_access_type='private')
    
    pulumi.export('container_name', container.name)

    Final Thoughts

    Cloud infrastructure has become more powerful, but also more complex. Managing it efficiently now requires more than just knowing your cloud provider; it requires using the right tools to bridge the gap between development and operations.

    Pulumi challenges the traditional way we think about infrastructure by letting us treat it as real code, versioned, tested, and maintained like the rest of our stack. It brings cloud engineering closer to software engineering, giving teams the clarity and control they need to scale with confidence.

    Whether you’re a developer tired of YAML or a team looking to unify your IaC approach across AWS, GCP, and Azure, Pulumi isn’t just another tool. It’s a shift in mindset.

    Get Expert Help with Pulumi​

    If you’re exploring Infrastructure as Code or want to implement Pulumi across AWS, GCP, or Azure, TardiTech can help you get there faster.

    Start building scalable, automated infrastructure with confidence. Let’s talk.