DEV Community

Cover image for What is Infrastructure as Code?
Ijay
Ijay

Posted on

What is Infrastructure as Code?

Learning cloud and DevOps is good, but in the process of learning, I’ve come to understand that Infrastructure as Code is very important.

In this article, I will cover

  • What Infrastructure as Code is and the problem it solves

  • The difference between declarative and imperative approaches

  • Why Terraform is worth learning

  • My reason for taking on this 30-day challenge

Let's get started

What is Infrastructure as Code (IaC)

From my reading, Infrastructure as Code means using code to manage and set up infrastructure instead of doing everything manually. It is mostly used by DevOps and cloud engineers to provision resources in the cloud.

What problem does it solve?

IaC solves a lot of issues, especially what people call click ops. Instead of going to the cloud console and clicking around, which can lead to mistakes, you define everything in code. This makes it easier to repeat the same setup and avoid errors.

What are the ways Terraform is defined?

There are two ways Terraform is defined in editors:

  • Declarative

  • Imperative

1.Declarative: means you describe what you want, and the tool figures out how to achieve it.

For example, if you want to create an S3 bucket in AWS using Terraform, you just write:

resource "aws_s3_bucket" "example" {
  bucket = "my-example-bucket"
}
Enter fullscreen mode Exit fullscreen mode

In the example above, you are only saying, "Create a bucket with this name.” Terraform handles how it will be created.

2.Imperative: means you define every single step to get the result.

For example, using AWS CLI:

aws s3 mb s3://my-example-bucket
Enter fullscreen mode Exit fullscreen mode

Which method is commonly used by developers?

In declaring a HashiCorp Configuration Language (HCL), most developers use declarative rather than imperative because you only define what you want, and the tool handles the process. It reduces errors and makes infrastructure easier to manage.

While imperative is useful for quick tasks, it is not for long-term and scalable systems. i.e., step by step

Why do we use Terraform basically

Terraform is used for provisioning infrastructure across different cloud providers. It is not limited to one cloud like CloudFormation, so it is more flexible and widely used.

My goal for the next 30 days

My goal is to challenge myself to build using IaC and stop relying on clicking around in AWS. I want to improve my skills, become better as a DevOps and cloud engineer, and get more comfortable building real things.

If this resonates with you, feel free to share it with others on a similar journey.


Other Helpful Resources


Stay updated with my projects by following me on Twitter, LinkedIn, and GitHub.

Thank you for reading

Top comments (0)