InfraSketch Tutorial

Our journey to help DevOps engineers automate the Terraform template creation process started in 2020. A year later, our product "InfraSketch" is ready for release.

APR 7, 2021 | ABHISHEK HUGAR
undefined

Our journey to help DevOps engineers automate the Terraform template creation process started in 2020. A year later, with a ton of elbow grease, our product, “InfraSketch” is ready for release. This blog will walk you through every component of the product and how a DevOps engineer can use InfraSketch to generate Terraform templates and spin up their infrastructure.

Interested in learning more? Join our Slack, led by DevOps experts, to meet other professionals and learn more about Terraform. We will also have more opportunities to engage closely with InfraSketch in the Slack.

What is InfraSketch?

InfraSketch is a Terraform template creation tool developed by InfraCode. The product has evolved from our previous open-source project InfraRapid, where you had to note down your infrastructure configurations in a YAML file and execute the executable Python file in order to generate the templates. However, this still required the DevOps engineer to be able to write the configurations manually in a YAML file. To make the lives of engineers easier, we created InfraSketch. In InfraSketch, you have a drawing board with configuration options to fill in. All you need to do is use the available components to sketch out your infrastructure on the board and the application will generate a fully coded Terraform template for you.

An Overview of InfraSketch

InfraSketch with grid switched off

InfraSketch currently has a black background with an optional grid. With the grid switched on, the application provides a grid on the background, which would serve the purpose of a better organization or alignment of your components. The application currently supports Amazon Web Services (AWS) and Microsoft Azure.

InfraSketch with grid switched on

All templates will have the default name “Untitled”, but you can also rename the template as you’d like. The template can be renamed by simply clicking on “Untitled” and then giving it a new name.

Let’s now go through each of the icons and their properties.

1. Server

The server is represented as a monitor on InfraSketch. To add a server to your template, you can simply drag and drop it. When you add a server to your template, a pop-up with fields to fill in appears on the right-hand side. This can be used to define the properties of your server.

Server properties and their definition:

1. Name: By default, the server names are defined as server-0, server-1, and so on. You can update the name of the server under this field.

2. Size: You define/select the size specifications of your server instance from the drop-down. Currently, we are using the naming conventions by AWS and Azure, but in the future, this may be modified to a cloud-agnostic naming convention. Example- t2.micro means that 1 virtual CPU will be allocated with 1GiB of memory.

3. Count: This property is used to define the number of servers with the same specifications that need to be created.

4. Operating System Image (AMI): You can select the type of OS that will be required from the list of options available in the dropdown here.

5. Elastic: This is a Boolean selection, where you may define whether your infrastructure will support elastic IP address selection or not.

6. Remote Command: Once your server and OS are set up on your infrastructure, there could be a few remote commands that you would need to be executed in order for your infrastructure to work as expected. You may define these commands that need to be executed here.

7. Inbound/Outbound Security rules: This section of the properties is used to filter the incoming and outgoing traffic to your server through the cloud provider. You can add the source, the port, and also the protocol that needs to be followed. You may also delete a rule that you have created here. For example- Source- All, Port-80, and Protocol- TCP.

8. Tags: If there are any Key-Value pairs that are required to be included in your configuration, you may enter them here. There are no restrictions on the number of entries that could be made.

9. SSH Key Path: You will have to specify the path of your SSH keys here. By default, the path is set to “~/.ssh/id_rsa.pub”. However, if your key is stored elsewhere, update the path accordingly.

II. Gateway

This is used to mention the region and the VPC IP address through which the instance needs to be set up on the cloud.

Gateway properties:

1. Region: This property is used to define the region where the infrastructure needs to be deployed on the cloud. A “region” is a broad spectrum of the geographical area where the data center of your cloud provider is present.

2. VPC Network: By default, the IP address here is set to “10.0.0.0/16”. You can update this as per your network requirement. The IP address mentioned here becomes your “main_cidr” value in your “.tfvars” file.

III. Load Balancer

A load balancer is responsible for managing the load on the network, passing it to all your backend servers. The load balancer receives the connection request and then attempts to establish a connection to one of the ports maintained under the listener configuration.


Load Balancer properties:

1. Name: By default, the load balancers will have the names “load_balancer-0”, “load_balancer-1”, etc. You may update the name to anything of your choice.

2. Listeners: These are key-value pair arguments, where you specify the list of ports that will act as the listeners for the load balancer.

3. Health: Under this property, you define the “Port”, “Path”, and the “Protocol” whose health or traffic density will have to be considered.

IV. Subnet

You may add a subnet to your main network by using this. A subnet is represented by the yellow-colored square box on the left-hand side of the web application.

Subnet Properties:

1. CIDR: You can define the subnet IP address here. The value mentioned here is maintained as the public and private subnet address in your “.tfvars” file.

2. Availability Zone (AZ): The availability zone is the available data centers within a particular region that was defined in the gateway. This is maintained as the public and private “subnet_az” in the “.tfvars” file.

V. Export button

Once you have sketched out and defined the properties of all the components, you may click on the “Export” button to generate the Terraform templates and store them as a zipped folder on your local system.

Use Cases for InfraSketch

Let’s now consider 2 simple use cases of creating Terraform templates using InfraSketch.

Use Case 1: Creation of 3 servers with Ubuntu-20.04 OS, on AWS provider in the us-west-1 region, with the following configuration:

Server1- 3 instances of a web server with a size specification of “t2.micro” and allowing both inbound and outbound traffic.

Server2- A simple database server of size “t2.micro” and allowing both inbound and outbound traffic.

Server3- A bastion server of size “t2.micro” and allowing both inbound and outbound traffic.

How to Create, Using InfraSketch:

The very first step, in this case, would be to specify the provider and the region. For this, I have selected the “AWS” provider. Then, I drag and drop the “Gateway” and specify the following properties:

Region: us-west-1
VPC Network: 10.0.0.0/16


Next, it’s important for my configuration that I also define the subnet and its properties before I start creating my servers. So, I add a subnet to the configuration with the following properties:

CIDR: 10.0.0.0/24
Availability Zone: us-west-1a

NOTE- If you are selecting the components from the list of icons on the left, do not forget to make the appropriate connections between them by using the arrow icons that appear next to the components when you click on them.

Now that I have my gateway and the subnet, I will first create the “Server1” with the following configurations:

Name: Server1
Size: t2.micro
Count: 3
Operating System Image(AMI): ubuntu-20.04
Elastic: True
Remote Command: I want to ensure that “Docker” is installed, run, and then “nginx” is run on docker. Therefore, I add these remote commands:

sudo apt-get update
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu
sudo docker run -d --name web -p 80:80 nginx
Security Rules: I will be allowing incoming traffic from ports 80, 443, and 22-25 with TCP protocol. The outbound traffic will be allowed completely.
Tags: Server Role: Web-server and OS: Ubuntu-20.04
SSH Key Path: ~/.ssh/id_rsa.pub


Similarly, I set up Server2 and Server3.

Now that I have drawn and specified the properties required for my configuration, I will click on export and save the Terraform template on my local machine.

Use Case 2: Creation of a load balancer and server with Ubuntu-20.04 OS, on AWS provider in the us-west-1 region, with the following configuration:

LB-Server1- 3 instances of a web server with a size specification of “t2.micro” and allowing inbound traffic.

How to Create, Using InfraSketch:

The first step of selecting the cloud service provider and configuring the properties of “Gateway” remains the same as in “Use Case 1”:


I will now add a load balancer to the configuration with the following properties:

Name: load_balancer-0
Listeners: 80: 8000
Health: The load balancer port whose health needs to be checked will be “8000” in this case with a path value of”/” and the “HTTP” protocol.

The next step will be to define the network or subnet properties for the server that I create next.


Finally, as required I will setup the server required with the following properties:

Name: LB-Server1
Size: t2.micro
Count: 3
Operating System Image(AMI): ubuntu-20.04
Elastic: True
Remote Command: I want to ensure that “Docker” is installed, run, and then “nginx” is run on docker. Hence, I add these remote commands:

sudo apt-get update
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository 'deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable'
sudo apt-get update
sudo apt install docker-ce -y
sudo usermod -aG docker `whoami`
sudo systemctl start docker
sudo systemctl enable docker
sudo mkdir /opt/html
echo \"<h1>This is a server</h1>\" | sudo tee /opt/html/index.html
sudo docker run -d --name web -v /opt/html:/usr/share/nginx/html -p 8000:80 nginx
Security Rules: I will be allowing only the incoming traffic from ports 8000 and 22 with TCP protocol.
Tags: Server Role: Web-server, load_balancer: web_lb, and OS: Ubuntu-20.04
SSH Key Path: ~/.ssh/id_rsa.pub

I will now click on export to save the “Terraform templates” on my local system.

--

We hope you enjoyed this quick sneak preview into our upcoming tool, InfraSketch. Looking to discuss more use cases for InfraSketch--or simply looking to find out more? Join our Slack community to connect with other DevOps professionals.

PS: Did you know we have weekly Jam sessions on DevOps topics? The weekly invites go out on our Slack and Twitter channels. We hope to see you there!