Your first day with Pulumi.

Your first day with Pulumi.

Day 1 with Pulumi overview

Prerequisites:

  • Create a pulumi account. pulumi.com
  • Understanding of Cloud Platforms Azure, AWS, GCP
  • Understanding of basic Software engineering principles. `Data Structures: Array, Lists. Conditional statements. etc,
  • knowing at least one of the following languages. C#, TS, Python
  • Able to use the terminal on your system, macOS, Windows Terminal

At a high-level Pulumi is a modern infrastructure as code platform. It leverages existing programming languages—TypeScript, JavaScript, Python, Go, and .NET—and their native ecosystem to interact with cloud resources through the Pulumi SDK. We are able to use Pulumi to manage our cloud infrastructure.

image.png

What is pulumi?

Pulumi is a tool that we can use for infrastructure as code, you can think of pulumi as a platform that we can use to manage our infrastructure via code; in the language of our choice.

What can we use Pulumi for?

We can use pulumi for managing our infrastructure via code; in the language of our choise C#, Javascript, Typescript, GO, Python. Using Pulumi we can manage our infrastructure this could be a Cloud provider if self like Azure, AWS or even managing DNS records via CloudFlare, Pulumi has many different providers that we have access to. View the following link to see a full list of Pulumi Registry | Pulumi

How can pulumi help us with our Infrastructure?

Pulumi can help us manage and deploy our infrastructure via code. This way we are able to programmatically apply our changes to our infrastructure in a manageable way.

In the following examples, we can see that we are using the C# language and we are using the Pulumi.CloudFlare; we also see that we are creating a new A record

Ex 1.0 - C# example using cloudflare provider.

using System.Collections.Generic;
using System.Threading.Tasks;
using Pulumi;
using Pulumi.Cloudflare;

class Program
{
    static Task Main() =>
        Deployment.Run(() => {
            var record = new Cloudflare.Record("sample-record", new Cloudflare.RecordArgs
            {
                Name = "my-record",
                ZoneId = "xxsdZoneIDhadf",
                Type = "A",
                Value = "192.168.0.11",
                Ttl = 3600,
            });
        });
}

Ex.1.1 - Python example of creating a static website with pulumi on aws.

import json
import mimetypes
import os

from pulumi import export, FileAsset
from pulumi_aws import s3

web_bucket = s3.Bucket('s3-website-bucket',
    website=s3.BucketWebsiteArgs(
        index_document="index.html",
    ))

content_dir = "www"
for file in os.listdir(content_dir):
    filepath = os.path.join(content_dir, file)
    mime_type, _ = mimetypes.guess_type(filepath)
    obj = s3.BucketObject(file,
        bucket=web_bucket.id,
        source=FileAsset(filepath),
        content_type=mime_type)

def public_read_policy_for_bucket(bucket_name):
    return json.dumps({
        "Version": "2012-10-17",
        "Statement": [{
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                f"arn:aws:s3:::{bucket_name}/*",
            ]
        }]
    })

bucket_name = web_bucket.id
bucket_policy = s3.BucketPolicy("bucket-policy",
    bucket=bucket_name,
    policy=bucket_name.apply(public_read_policy_for_bucket))

# Export the name of the bucket
export('bucket_name', web_bucket.id)
export('website_url', web_bucket.website_endpoint)

In the above example, we saw how was can call and use different pulumi providers, this could be a part of a bigger pipeline that we use while deploying application and services.

Side Note: When using pulumi providers, it is always a good idea to reference the Pulumi documentation. to know what type of args are available to us. Pulumi Registry | Pulumi

What languages can you use with pulumi?

Pulumi is a multi-language infrastructure as a code tool. Each language supports the entire surface area of all of the clouds available in Pulumi Registry

The current language that is supported. JavaScript, TypeScript, Go, Python, C#

Pulumi is open source, so it is possible to add your own language. If you have questions, you can rech out to the Pulumim Team here --> contact us and let them know what you’re looking for.

Questions

Before moving on you should be able to answer the following questions.

  • What is pulumi?
  • What can we use Pulumi for?
  • How can pulumi help us with our Infrastructure?
  • What languages can you use with pulumi?

Summary

  • Pulumi is a good tool for managing your cloud, PaaS infrastructure, and managing service on AWS, Azure, GoogleCloudPlatform can be easily maintained.
  • Another good resource to check out is the FAQ | Pulumi
  • Be sure to join the Pulumi Slack community to stay connected, also a good place to ask questions as well.

Did you find this article valuable?

Support Jordan Taylor by becoming a sponsor. Any amount is appreciated!