Using Pulumi for Rapid Deployment

This is a submission for the Pulumi Deploy and Document Challenge: Fast Static Website Deployment What I Built Hello Dev Community! Here's hopefully the first of many posts and attempts at these kinds of challenges. The project I built is in C# and leverages the Google Bucket Storage to rapidly prototype static websites by simply dropping the compiled site into a folder. Live Demo Link http://storage.googleapis.com/bucket-site1-9e13468/index-48A01530.html http://storage.googleapis.com/bucket-site2-ee21e84/index-90BB84EE.html http://storage.googleapis.com/bucket-site3-f0559b4/index-88A85004.html Project Repo celopez3 / MyFirstPulumi My first Pulumi project for the DEV competition Creating Static Websites Using Pulumi Infrastructure as Code This project was created for entry into the DEV Challenge sponsored by Pulumi. The main function of this project leverages the Pulumi .NET SDK to create index.html driven websites in the form of Google Cloud Bucket Storage allowing for rapid static website deployments from a single folder. Pre-Requisites & Requirements This project is in C# and will require 1. Visual Studio Code (although any Visual Studio will work) 2. Pulumi CLI 3. Google CLI 4. Google Cloud

Mar 31, 2025 - 03:56
 0
Using Pulumi for Rapid Deployment

This is a submission for the Pulumi Deploy and Document Challenge: Fast Static Website Deployment

What I Built

Hello Dev Community! Here's hopefully the first of many posts and attempts at these kinds of challenges. The project I built is in C# and leverages the Google Bucket Storage to rapidly prototype static websites by simply dropping the compiled site into a folder.

Live Demo Link

http://storage.googleapis.com/bucket-site1-9e13468/index-48A01530.html
http://storage.googleapis.com/bucket-site2-ee21e84/index-90BB84EE.html
http://storage.googleapis.com/bucket-site3-f0559b4/index-88A85004.html

Project Repo

GitHub logo celopez3 / MyFirstPulumi

My first Pulumi project for the DEV competition

Creating Static Websites Using Pulumi Infrastructure as Code

This project was created for entry into the DEV Challenge sponsored by Pulumi. The main function of this project leverages the Pulumi .NET SDK to create index.html driven websites in the form of Google Cloud Bucket Storage allowing for rapid static website deployments from a single folder.

Pre-Requisites & Requirements

This project is in C# and will require

1. Visual Studio Code (although any Visual Studio will work)
2. Pulumi CLI
3. Google CLI
4. Google Cloud 

Once you have installed the clients, you will need to make sure you have your Google Cloud Project ID. If you're new to Pulumi I would recommend reading my article on Dev.to which covers the basic installation experience or you can get it straight from Pulumi.

git clone https://github.com/celopez3/MyFirstPulumi.git
cd MyFirstPulumi
$env:GCP_PROJECT_ID=""

Deployment

To deploy this project run

pulumi

My Journey

Since this was my first time working with Pulumi I decided it best that I start with the documentation and creating an account. I quickly learned that installing the Pulumi CLI was a necessary first step.

I followed the steps in Getting Started with Pulumi and Google Cloud. I usually have chocolatey installed but at the time of doing this I had to settle for the AMD64 MSI package. Afterwards running

Console commands: pulimi version

from a Powershell will verify that the installation was successful. I already had .NET8 installed but the guide has a link if you need to install it.

Finally, I needed to choose a cloud framework, and typically by choosing C# you'd probably expect me to choose Azure, but I ran into issues getting my Azure account setup because of my phone number. I submitted a ticket and did get it resolved but not until after I decided to move forward with Google Cloud Platform and install the GCloud CLI.

At this point you should create a project for yourself using the Google Console. If you aren't familiar, check out Google's documentation and use the Manage Resources button as a shortcut.

When the GCloud CLI is finsihed it will open a command prompt for the following steps to be completed:

1) sign in with your Google Account
2) select a project.

Successful installation of the GCloud CLI as displayed in a console window

Once you have authenticated your projects will be listed and you'll select which project should be used in my case I create a project named "pulumi".

Now that we've got our environment set up, we should open a Powershell console and navigate to wherever you want the code created and run the following commands:

Console Commands: mkdir quickstart, pulumi new aws-csharp

The first command creates a folder quickstart and navigates into it. The second command calls the pulumi cli to create an aws-csharp project, except in my case I ran

pulumi new gcp-csharp

If this is your first time executing pulumi you will be prompted to login and setup the connection between Pulumi Cloud and the CLI. Following the rest of the guide will get you to being able to deploy a static website to Google Buckets. This was a really cool start, but I wanted to expand on it.

My project addresses three scenarios for streamlining rapid prototypes to Google Buckets as static webpages. The first scenario is a default html template probably setup by hand.

HTML header showcasing minimal CDN inclusions and one local script

From the tag you can see a minimal Bootstrap5 and a local style.css. The body was setup from the Boostrap5 Templates, specifically the Blog template.

The second scenario is a Next.js or post compiled project, basically one a static website that was exported. I first downloaded a Startup Next.js template from GitHub.

I added this line to the next.config.js:

output: 'export'

Which basically compiles your Next.js project into a folder called 'out' when you run:

npm run build

Finally, the third scenario is simply downloading a free html template, extracting and launching the files.

Using Pulumi

You'll find all the primary work for my submission in the Program.cs file. I first created a directory called websites and for purposes of rapidly deploying sites I created 3 folders, site1, site2, and site3. Each folder contained files related to each scenario listed above.

I then use pulumi to create buckets for each site.

C# code using Pulumi to create a Google Cloud Bucket

Once the buckets were created, I loop through each site directory and create Bucket Objects for each file, including subdirectories.

Running pulumi up from the folder containing Program.cs results in, specifically the index.html file being uploaded and the auto deployed site urls being displayed.

Results of running console command: pulumi up

It is important to note that the code within my repo is hard coded to leverage index.html, however it could easily be adapted to accommodate any html files.

Lessons Learned & Conclusions

I definitely learned a lot throughout this process. I went down quite a few rabbit holes before I decided on this submission. I wouldn't say that my experience with Pulumi felt easy, but I never felt stuck or unable to find an answer. Their online documentation and the availability of examples really helped accelerate my overall experience. Most importantly, now that I have this project I'll be able to rapidly prototype website templates by simply dropping them into a folder.

I see a lot of potential in Pulumi and look forward to the next project. If I had more time I'd like to submit a docker deployment solution through Pulumi, but I doubt I'd get it done before the April 6th deadline.

Let me know if you have thoughts or questions in the comments and thank you for your consideration.