Infra As Code

Infra As Code

Understand how to automate your cloud deployment.

20 de agosto de 2021

Iaac cover

Cloud computing brings us many advantages, since just a few clicks are enough to provision a resource in the cloud. However, as projects grow, those few clicks become tedious and an obstacle to project growth.

Imagine having to repeat those clicks every time you need to create a new environment, or a new project.

Well, in that case, you would have to manually repeat all the procedures to create your resources in the cloud.

And worse, imagine getting a parameter wrong? Just configure the wrong machine size or choose the wrong settings to create an environment different from what you need, and there we have a project with failures.

And as if that weren’t enough, how long will it take you to discover the failure? And how long will it take to fix?

Well then. Thinking about these pain points, very interesting concepts have emerged that more and more companies are adopting every year.

This is what we call Infrastructure As Code, or in its abbreviation, IaC. 

But after all, what does Infrastructure As Code (IaC) mean?

Infra as Code uses a high-level language (usually following the .json or .yaml pattern) to describe the characteristics of each resource we want to create in our cloud. These files are commonly called templates.

Thus, in the same way that you ‘version’, set rules and automatically deploy applications, the same can be done with your entire infrastructure.

This is because your infrastructure is stored in code format and whenever a change is needed, it is possible to use some versioning tool, such as git, for example, to manage your changes.

In fact, this management can also be done with our git flow, the Z-Flow. Want to know more? Click here!

What are the advantages of using Infrastructure As Code (IaC)?

  • Environment standardization: With infrastructure “written”, your team is not subject to errors when creating multiple environments.
  • Rule configuration: With the possibility of someone reviewing your infrastructure before provisioning it, you can configure review rules so that your infrastructure follows a certain standard. This way, you can block, for example, a template that does not contain tags, that is not approved.
  • Maintaining an update history: With the possibility of versioning your infrastructure, you automatically maintain an update history and can more easily track any modification in your infrastructure.
  • Process automation: Your team doesn’t need to waste time creating all the infrastructure for new projects. Similar projects can reuse templates and, by modifying just a few parameters, a new infrastructure is created quickly.
  • Parameterization: Templates allow parameterizing names, tags, links between resources and even identifying whether resources will be created or not. This makes it flexible to create templates to develop infrastructures suited to your needs. Thus, a single template can serve different needs just by changing its parameters. Continuous creation is standardized and organized, but parameterization adapts the template to what is specific to each environment. Let’s look at some examples:
  • Two identical environments, but one with resources created in the United States and another in Brazil.
  • A single template that creates a virtual machine, but in the development environment the machine type is simpler than in production.

Infrastructureascod

How to start using Infrastructure As Code (IaC)?

There are several tools that help us create templates when it comes to Infrastructure As Code (IaC).

Cloud providers have their own services for creating templates, such as AWS CloudFormation.

There are also generic tools that serve as templates for multiple providers, such as Terraform.

What is the adoption of Infrastructure As Code (IaC) in the market?

Infrastructure As Code (IaC) is just one of the many possibilities within the DevOps world, a sector that has been growing significantly in recent years.

According to a research, many companies have already adopted some IaC tool or plan to adopt one. 

After all, with so many benefits, why would your team be left out of incorporating this tool into their daily routine?

What has Zappts been doing when it comes to Infrastructure As Code (IaC)?

Here at Zappts, we have already adopted the use of templates in 100% of our projects.

The templates are parameterized so that we can easily deploy the same infrastructure to multiple environments. 

Want to see a real example of how this is done? Come with us 🙂

Here we usually use the CloudFormation tool, AWS services for resource provisioning. 

How does the AWS CloudFormation tool work? 

Let’s go!

CloudFormation requires a file, which can be written in .json or .yaml. The complete documentation of the resources can be found here. 

Let’s analyze the anatomy of a template:

AWSTemlateFormatVersion: ‘2010-09-09’
Description: ‘Example Template’

Parameters:
 Stage:
   Type: string
   Default: dev

Resources:
 DynamoResourceExample:
   Type: AWS::DynamoDB::Table
   Properties:
     TableName: !Sub ${Stage}_table
     KeySchema:
       – AttributeName: hash_key
         KeyType: HASH
     AttributeDefinitions:
      – AttributeName: hash_key
     AttributeType: S
     BillingMode: PAY_PER_REQUEST

The template above creates a DynamoDB table in AWS. In “Parameters”, we can define the identification of this resource’s environment, which is used to create the table name, with the !Sub property.

Notice that for each resource it is necessary to describe its characteristics so that the resource is provisioned adequately. In the documentation, we find which properties are mandatory and how to fill them in.

The deployment of these templates is done via pipeline, where we use AWS CLI commands to deploy.

This way, all infrastructure creation is done securely, automatically, with the minimum possible effort and maximum assertiveness.

Git zappts

Zappts Git Repository

Furthermore, aiming to disseminate knowledge, Zappts has a public repository with several template examples where Zappters and the community can reuse templates and accelerate the creation of new cloud infrastructures. 

The repository also has very nice documentation explaining how to use some examples and even some specific CloudFormation properties.

Check out the repository: https://github.com/zappts/zappts_cfn_templates 

Did you like this article? Follow Zappts and stay tuned for the next ones!

Want to learn more about Infrastructure As Code (IaC) for free?

Join our “Infrastructure as Code and CloudFormation” training, held on October 14, 2021.

Thauthau

This article was developed by Thauany Moedano, Head of Architecture and Back-end at Zappts.