Introduction
Pulumi is a modern infrastructure as code platform .
what is Infrastructure as code?
Let's break it down in simple terms, suppose we have some infrastructure already running, for example, some servers, Ec2 instances, clusters or something like that which is basically an infrastructure so you can obviously do that manually one by one which can be a tedious task sometimes here comes in the picture some infrastructure as code platform Like Pulumi, Terraform etc
let us suppose such platforms are a Santa you give them a list of your requirements for the infrastructure and then the Santa make your list of wishes come true and your infrastructure is up and ready, with no need of configuring it manually. So here the question is why Pulumi and why not any other tools?
Why Pulumi ?
how is it diffrent
Infrastructure as code is usually written in Domain-specific language for eg: HCL for Terraform and JSON or YAML files But what if we need to add some more logic to it? like conditionals or loops or some functions to reuse the logic. Any programming language is capable of such kind of logic. writing the same infrastructure as code logic would obviously make writing more complex code easier and cleaner so here comes in picture Pulumi : Pulumi allows you to write Iac in a standard programming language
Which programming language is that?
Pulumi supports almost every programming language so no need to learn a new language go ahead with the language you already know and love. how does it help?
Suppose you are working as a python developer. so as a developer you are already familiar with the language and plugins and all the modules which are required as a python developer you can sum up all that and write infrastructure as code and work closely with the operations team for testing and deploying the infrastructure smoothly
Architecture
Programs reside in a project, which is a directory that contains source code for the program and metadata on how to run the program. After writing your program, you run the Pulumi CLI command pulumi up from within your project directory. This command creates an isolated and configurable instance of your program, known as a stack. Stacks are similar to different deployment environments that you use when testing and rolling out application updates. For instance, you can have distinct development, staging, and production stacks that you create and test against.
Deep dive
Pulumi provides us with a large number of combinations between the cloud providers like AWS, google cloud and different programming languages you can choose the cloud + language combination you are familiar with and start deploying your infrastructure not only that you can also import your existing infrastructure into Pulumi or if you are using any other infrastructure as code platforms like Terraform you can convert that as well and use it in Pulimi and a lot more. which can help you with
Tame modern cloud complexity
Bring the cloud closer to application development
Use engineering practices with infrastructure
Foster collaboration and innovate faster
Your Cloud , Your Language , Your way
Demo
A lot of theory part has been covered now let's get some real hands-on experience so first thing first you can go ahead and sign in and install Pulimi with your preferences based on the options provided
Lets create a folder
mkdir pulimi
cd pulumi
in this folder we are gonna create a pulumi project and to bootstrap the project pulumi gives us the boilerplate code to get started with and we can do that using
Pulumi new
this command will help you choose the template based on the cloud provider + Programming language
As we are going to create resources on Aws with javascript . after that lets enter our project information
Project name : Myproject Description : (A minimal AWS javascript Pulumi program) stack name: dev Aws region and now our project is ready to go !
ls
pulumi as genreated a lot of files here you have index.js where all the modules are loaded
"use strict";
const pulumi= require("@pulumi/pulumi");
const aws = require("@pulumi/aws");
const awsx = require("@pulumi/awsx");
// Create an AWS resource (S3 Bucket) I
const bucket = new aws.s3.Bucket ("my-bucket");
// Export the name of the bucket
exports.bucketName = bucket.id;
To execute a Pulumi project all you need is
Pulumi up
Now it will give you a preview of what's gonna happen and ask for a final confirmation
That was a basic deployment of infrastructure , now lets make it a bit more meaningful lets create multiple buckets in a loop
"use strict";
const pulumi= require("@pulumi/pulumi");
const aws = require("@pulumi/aws");
const awsx = require("@pulumi/awsx");
var buckets = ["bucket-one","bucket-two","bucket-three"]
var export_names = []
buckets.forEach(function(name){
const bucket = new aws.s3.Bucket(name);
export_names.push(bucket.id)
})
// Export the name of the bucket
exports.bucketName = export_names;
Now we gonna do
Pulumi up
And tadaaa!
Conclusion
Now we have understood the concept of Pulumi and its use cases I hope you have gotten the knowledge and why it is easy to use. so go ahead and have a look at some important links mentioned below Documentation
Go check-out get your hands dirty start learning and deploy your infrastructure on the go!
Bonus
A quick tip if you are using any other tools for your infrastructure here's how you can convert in and apply it to Pulumi Converters