Creating Infrastructure Components with Pulumi and Bit
source link: https://blog.bitsrc.io/creating-pulumi-aws-components-with-bit-4c3691eb0adb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Creating Infrastructure Components with Pulumi and Bit
Write once and use everywhere by breaking down modern IaC into independent components
With Pulumi, you can write your Infrastructure as Code (IaC) with popular programming languages like JavaScript and TypeScript. In addition, it already supports a range of Cloud providers, including AWS, Azure, GCP.
This article will explain how I used Pulumi with Bit by creating modular components for Infrastructure in code.
You can find the Pulumi Component I’ve created with Bit Here. In addition, my sample IaC code consuming the Pulumi component can be found Here.
Why Pulumi with Bit?
If you have a simpler infrastructure with few modules, you can maintain it within a Pulumi stack. But when you are trying to structure a Pulumi code with hundreds of thousands of modules, you may probably need to think of a way to make your code modular, reusable, readable, and maintainable.
Besides, when you write code with Pulumi, you might feel that your code is getting bigger and lengthier, creating a monolith.
And, knowing the capabilities of Bit and Pulumi, I wanted to experiment, whether we can combine both to get the best out of both worlds.
Encapsulating Pulumi Code as an Independent Component
Here, I used a static website on an AWS S3 bucket. You can see that I have used Pulumi’s powerful IaC features to set up the AWS resources I need.
Before using Bit with PulumiWhen I execute the pulumi up
command in the terminal, it creates the below infrastructure on my AWS account and deploys my static website content as shown below.
While preserving the same functionality, I moved the S3 bucket creation code into an independent component and exported it to a Bit Scope (@yasasw/demo-scope.storage.s3).
Then, inside my Pulumi stack, you could use it as follows;
After using Bit with PulumiThough this is a simple example, you can carry out the same for any complex Pulumi code block that you want to isolate from the rest of the components. Besides, you can use them across projects.
Step by Step Guide
I will explain the step-by-step process I followed to migrate my Pulumi code to Bit as a component.
Step 1: Install Bit on the local machine
I first used @teambit/bvm
package to set up Bit on my machine, following the quick start guide.
Then I initialized a Bit workspace locally with the below terminal command.
bit new react-workspace <my-workspace-name>
Step 2: Create a component in a Bit workspace
Bit provides some ready-to-use templates like React buttons. However, I wanted to create a custom Bit component to migrate my existing Pulumi S3 bucket service code. So first, I created a dummy component using,
bit create react-component storage/s3
Then I added my Pulumi S3 bucket creation code to a new file as bucket.ts
. Next, I moved my external resources (a favicon and an index.html).
After these steps, my local Bit folder structure was like below,
storage/s3
├── www (directory with external html resources)
├── index.ts
├── bucket.compositions.tsx
├── bucket.docs.md
└── bucket.ts
After that, I had to pack these files and export them to a Bit remote scope.
Step 3: Create a remote scope in Bit cloud
First, I’ve created an account in https://bit.dev. Then I‘ve created an organization (You can proceed without creating an organization as well).
After the initial account setup, I clicked on the “new button” to create a new scope on Bit to store my component. It was a pretty straightforward task, thanks to excellent documentation.
Note: After creating a Bit workspace, don’t forget to update the value of
defaultScope
atworkspace.jsonc
file with your newly created username/organization name and your scope value. And also, I manually changed my workspace into a Node environment following Bit documentation.
Step 4: Export component to Bit
The ability to version your Bit components with tags is another cool feature that you can enjoy. For example, I tagged my components using the below command before exporting the task.
bit tag --all --message "first version"
Next, I logged into Bit remote scope via my terminal to authenticate,
bit login
Finally, I used the below command to export my local independent component to my remote scope.
bit export
Hurrah! I could see my Pulumi component live on Bit cloud.
Note: Pulumi specific unit tests written in the “Mocha” and “Chai” frameworks are still not supported by the Bit. However, I got to know from the Bit community that the support will come soon.
The best part of breaking down Pulumi code into independent components
When your component is exported to Bit, you can keep it as a Public or Private component. In addition, Bit provides a dedicated page for your component, including interactive docs and different compositions of your component usage and more;
- Component Sharing — Share my components across other applications and among different developers.
- Dependency Management — All the dependencies are managed by Bit so that I do not need to worry about it.
- Component Versioning — Maintain different versions of the same component, including a changelog.
- Component Testing — Bit supports execution of unit tests in-house, ensuring the expected component functionality.
Recommend
-
7
GitHub Actions help automate tasks within your software development life cycle. At Pulumi, we use GitHub Actions internally as part of every build/release cycle, and we run these tasks many, m...
-
8
How Pulumi Compares to Terraform for Infrastructure as Code📅 December 21, 2018 – Kyle GalbraithI have been a huge fan of Terraform for a lot of my recent work. There is something about the modularity it brings to infrastructur...
-
12
-
7
Introduction to Infrastructure as Code on Azure using Python with PulumiJanua...
-
4
初探 Infrastructure as Code 工具 Terraform vs Pulumi 想必大家對於 Infrastructure as Code 簡稱 (IaC) 並不陌生,而這個名詞在很早以前就很火熱,本篇最主要介紹為什麼我們要...
-
4
Why Pulumi?Pulumi, an IaC tool released in mid-2018, seems to address this problem well. As a result, it is rapidly becoming one of the most popular IaC tools out there.Let’s investigate why many DevOps teams have st...
-
6
Infrastructure as Code on AWS using Go and Pulumi When we talk about Infrastructure as Code or IaC, the first tool that comes to min...
-
6
Migrating My Infrastructure From Terraform to Pulumi Posted on Tuesday, Feb 22, 2022 Pulumi community member
-
4
Announcing Infrastructure as Code with Java and PulumiPosted on Wednesday, May 4, 2022Today we are excited to announce the preview of Java support for all of your modern infrastructure as code needs. This anno...
-
12
Pulumi infrastructure-as-code goes universal to build cloud apps
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK