HomeVideos

How Terraform changed software engineering forever

Now Playing

How Terraform changed software engineering forever

Transcript

323 segments

0:00

Stop clicking. You think Netflix or Uber

0:02

spins up 5,000 servers by clicking

0:04

create instance 5,000 times? No. They

0:08

define a blueprint. They run a single

0:10

command and an entire data center

0:12

appears out of thin air. That is why

0:14

Terraform is everywhere. It is the only

0:17

way to survive at scale. It turns your

0:19

infrastructure into software. If you are

0:22

still building servers by hand, you are

0:24

building a house of cards. Stop being a

0:26

server mechanic and become a cloud

0:28

architect. At its core, Terraform is an

0:31

open-source infrastructure as code tool

0:33

created by Hashacorp. It allows you to

0:35

define, provision, and manage cloud

0:37

infrastructure using human readable

0:39

configuration files. Think of it as a

0:41

blueprint for your data center. Instead

0:43

of manually clicking buttons in the AWS,

0:46

Azure or Google Cloud consoles, which is

0:48

slow and hard to replicate, you write a

0:50

text file describing your desired end

0:52

state. Terraform then reads that file

0:54

and handles the complex logic to make it

0:56

a reality. A key distinction of

0:59

Terraform is that it is declarative, not

1:01

imperative. Imperative or scripting

1:04

would involve telling the computer how

1:06

to do something. For example, log in,

1:08

click create server, wait 5 seconds, and

1:11

then install update. In Terraform, which

1:13

is declarative, you tell the computer

1:15

what you want. For example, I want three

1:17

servers with a load balancer like

1:19

EngineX. Terraform figures out the how

1:22

and the order of operations for you. So,

1:24

why use Terraform? Before Terraform,

1:26

managing infrastructure was manual via

1:28

click ops and very errorprone. If you

1:31

needed 10 servers, you created them one

1:33

by one. If a configuration drifted, for

1:35

example, a junior engineer manually

1:37

opened a firewall port for testing and

1:40

forgot to close it, it was nearly

1:42

impossible to track. Terraform solves

1:44

these specific engineering challenges.

1:46

First, item potency. You can run the

1:48

same Terraform code multiple times and

1:50

the result remains the same. If the

1:53

server already exists, Terraform won't

1:56

create a second one. It simply verifies

1:57

the existing one matches your code.

1:59

Second, infrastructure as code. Your

2:02

infrastructure is stored in Git. This

2:04

enables version control, meaning you can

2:06

roll back to previous infrastructure

2:08

versions if a deployment breaks. It also

2:10

enables code reviews. Peers can review

2:12

infrastructure changes via pull requests

2:14

before they go live. And finally, audit

2:16

trails. You know exactly who changed

2:18

what and when. And third, it is platform

2:21

agnostic. While you write specific code

2:24

for AWS or Azure, Terraform provides a

2:27

unified workflow for all of them. You

2:29

can even manage multiple clouds. For

2:31

example, AWS for compute, Cloudflare for

2:33

DNS in a single configuration. But how

2:36

does it work? What is the core workflow?

2:38

Terraform follows a strict life cycle

2:41

that ensures safety and predictability.

2:43

Starting with Terraform init, this is

2:46

the initialization step. Terraform scans

2:49

your code, identifies which providers

2:51

you are using, for example, AWS, and

2:53

downloads the necessary plug-in binaries

2:55

to a hidden Terraform folder. This is

2:58

followed by Terraform plan. This is a

3:00

safety check. Terraform compares your

3:02

code against your current live

3:04

infrastructure and creates an execution

3:06

plan. It shows you a diff, green for

3:09

additions, red for deletions of exactly

3:11

what will happen. This is a readonly

3:14

operation. Next is Terraform apply. This

3:17

is the execution. If the plan looks

3:19

correct, you confirm it. Terraform makes

3:22

the API calls to the cloud provider to

3:24

build or modify the infrastructure to

3:26

match your code. And last but not least,

3:29

Terraform destroy, which is the cleanup.

3:31

When an environment like a testing

3:33

sandbox is no longer needed, this

3:35

command reads your state file and

3:37

removes all associated resources

3:39

efficiently. But how does Terraform

3:41

actually work under the hood? To

3:44

understand why Terraform is so reliable,

3:46

you need to look at its internal

3:47

architecture. It isn't just one big

3:49

program. It's a modular system. The

3:52

first is the Terraform core or the

3:54

brain. This is the static binary you

3:57

download from Hashacorp. It is the

3:58

engine that drives everything. But

4:00

remarkably, it knows absolutely nothing

4:02

about AWS, Azure or Google Cloud. Its

4:05

job is strictly logical. It reads your

4:07

config by parsing your TF files and

4:10

validating the syntax. It also manages

4:12

state by maintaining the terraform.tf

4:15

state file which acts as its map of

4:17

reality. By reality, we mean the actual

4:20

live infrastructure currently running in

4:22

the cloud. The core uses this file to

4:24

link your abstract code like resource

4:27

web server to the specific real world ID

4:29

like AWS ID I-01 33 4 5 6 7 8 9. If you

4:34

delete this file, Terraform loses its

4:36

memory and forgets that your servers

4:38

even exist, often requiring manual

4:40

cleanup. It also calculates the resource

4:42

dependency graph, a directed asyclic

4:45

graph. It figures out that the database

4:47

needs the subnet which needs the VPC.

4:50

And second is the providers or plugins.

4:53

These are separate binaries or

4:54

executable files that the core downloads

4:57

during Terraform init. The AWS provider,

4:59

for example, is a Go binary that knows

5:01

exactly how to make API calls to AWS.

5:04

Since the core doesn't know AWS or Azure

5:08

or Google Cloud, it uses plugins called

5:10

providers. These are small binaries that

5:13

the core talks to via RPC. The core

5:16

says, I need a resource of type AWS

5:18

instance created. The AWS provider says,

5:22

okay, understood. I will translate that

5:24

request into a run instances API call

5:27

and send it to the AWS endpoint. This

5:29

separation is why Terraform is so

5:31

powerful. Hashorp updates the core to be

5:34

smarter while AWS updates their provider

5:37

to support new features and they work

5:38

together seamlessly. When you run

5:40

Terraform plan, Terraform builds a

5:43

mathematical representation, a directed

5:45

asyclic graph of all your resources. It

5:48

looks at your code and sees that the EC2

5:50

instance refers to the subnet ID.

5:52

Therefore, it knows the subnet must

5:55

exist before the EC2 instance. It walks

5:57

this graph to determine the exact order

5:59

of operations. Because it has this

6:02

graph, Terraform can identify resources

6:04

that don't depend on each other and

6:06

create them in parallel. For example,

6:07

creating a database and a load balancer

6:10

at the same time, which speeds up your

6:12

deployment significantly. In a modern

6:14

production environment, Terraform is

6:16

just one piece of a much larger puzzle

6:18

involving cloud architecture and

6:20

AIdriven automation. This is where

6:22

CodeCloud becomes your secret weapon.

6:24

They've moved beyond just DevOps to help

6:26

you master the new skill stack. DevOps,

6:29

cloud, and AI all in one place. What

6:32

makes CodeCloud different is their lab's

6:34

first philosophy. Instead of just

6:36

watching guided videos, you're dropped

6:38

into real browser-based environments

6:40

where you can deploy multicloud

6:42

infrastructure, manage Kubernetes

6:44

clusters, and even experiment with AI

6:46

assisted workflows. They've recently

6:48

integrated a personalized AI tutor right

6:50

into the labs. So, if your Terraform

6:52

plan fails or a container won't start,

6:55

you get realtime intelligent guidance to

6:57

help you troubleshoot just like a senior

6:59

engineer looking over your shoulder.

7:01

Whether you're following their 100 days

7:03

of DevOps challenge, or diving into

7:05

their new AI engineering tracks, you're

7:07

building a portfolio of realworld

7:09

projects that actually mean something to

7:11

recruiters. If you're ready to stop

7:12

watching and start building, use the

7:15

link in the description to check out

7:16

their latest learning paths. Thank you

7:18

to CodeCloud for sponsoring this video.

7:20

Now, let's get back to Terraform. To

7:22

master Terraform, you must understand

7:24

the components that power it. First, the

7:26

providers. Terraform is just the core

7:28

engine. It doesn't know how to talk to

7:30

the cloud by default. It uses providers

7:32

or plugins to translate Terraform syntax

7:35

into specific API calls. Note that

7:37

providers are not just for clouds. There

7:39

are providers for Kubernetes, Data Dog,

7:42

GitHub, and even ordering Domino's

7:44

Pizza. The second are resources. A

7:46

resource is the most important element.

7:48

It describes a specific infrastructure

7:51

object. It uses syntax like resource

7:53

followed by the type and the local name.

7:56

For example, AWS S3 bucket could be the

7:58

type and it could be named my data

8:00

bucket which is the local name used to

8:02

reference it elsewhere in code. Next is

8:05

state which is the brain of Terraform.

8:07

It's the most critical concept.

8:09

Terraform keeps track of the

8:11

infrastructure it manages in a file

8:13

called terraform.tfstate.

8:14

It maps your code for example resource A

8:17

to the real world ID. It caches resource

8:20

attributes so Terraform doesn't have to

8:22

query the cloud API for every single

8:24

detail every time. In prod, you never

8:27

store this file on your laptop. You

8:29

store it remotely, for example, inside

8:30

an AWS S3 bucket, so your entire team

8:33

shares the same view of reality. This

8:35

also enables state locking, which

8:38

prevents two people from modifying infra

8:40

at the exact same time. And finally,

8:42

modules. As you scale, putting

8:44

everything in one single file becomes

8:46

messy. Modules allow you to group

8:48

resources together into reusable

8:50

components. You can write a web server

8:53

module once and reuse it for your

8:55

staging, QA, and prod environments just

8:57

by passing different parameters. Here is

9:00

a more realistic example that uses

9:02

variables to avoid hard coding and

9:05

outputs to return useful data. How about

9:08

Terraform versus tools like Anible? It's

9:10

common to be confused by the landscape

9:12

of tools, so here's a breakdown.

9:14

Terraform is for provisioning. It's best

9:16

at creating the skeleton of your infra.

9:18

It creates the VPCs, subnetss, load

9:20

balancers, and bare servers. And it

9:23

follows an immutable model. If a server

9:25

is broken, destroy it and build a new

9:27

one. Anible, Chef, Puppet, etc. are used

9:30

for configuration management. It's best

9:32

at fleshing out the servers. Once the

9:34

server exists, these tools install

9:36

software, patch kernels, and manage user

9:39

accounts. They often follow a mutable

9:42

model, which means updating the existing

9:44

server in place. Most modern companies

9:46

use Terraform to spin up the infra

9:48

including Kubernetes clusters and then

9:50

use tools like Helm or Ansible to manage

9:53

the applications running inside. But you

9:55

might be wondering why Terraform why not

9:57

just use AWS cloud formation or anible.

10:00

Terraform didn't just get lucky. It

10:02

solved three specific problems better

10:04

than anyone else. The first is the cloud

10:06

agnostic advantage. Tools like AWS cloud

10:09

for Azure ARM templates are powerful but

10:12

they lock you into one vendor. If you

10:14

learn cloud form, you only know AWS.

10:16

Terraform is universal. You learn one

10:18

syntax, HCL, and you use it to manage

10:21

AWS, Azure, Google Cloud, Kubernetes,

10:24

Data Dog, and even GitHub. It allows you

10:26

to build a multicloud strategy without

10:28

learning five different languages. The

10:30

second is the immutable mindset versus

10:32

configuration management. Tools like

10:34

Ansible, Chef, and Puppet were designed

10:36

for a different era. They focus on

10:38

changing existing servers, i.e. mutable

10:41

infrastructure, installing updates,

10:43

patching configs, and tweaking settings.

10:46

Terraform focuses on replacing servers,

10:48

i.e. immutable infrastructure. In the

10:51

cloud era, if a server acts up, you

10:53

don't spend hours fixing it. You shoot

10:55

it and you spin up a new perfect copy.

10:58

Terraform is built native to this

11:00

disposable mindset. And the third is the

11:02

massive ecosystem, the provider model.

11:05

Because Terraform is open- source and

11:06

plug-in based, the community exploded.

11:08

Need to manage a firewall? There's a

11:10

provider for that. Need to configure a

11:12

Spotify playlist? There's also a

11:14

provider for that. This pluggable

11:16

architecture meant that Terraform grew

11:17

faster than any single company could

11:19

build it. It became the standard API for

11:21

the entire internet. To wrap up,

11:23

Terraform is the bridge between your

11:24

code and the cloud. It replaces the

11:27

fragile chaos of manual click ops with a

11:29

single version controlled blueprint. It

11:31

is declarative. You define the what, the

11:34

end goal, and Terraform figures out the

11:36

how or the API calls. It is stateaware.

11:40

It manages the terraform.tf state file

11:42

to track the reality of your infra

11:44

ensuring that what is running in the

11:46

cloud matches exactly what is written in

11:48

your code and it is universal. Whether

11:50

you are managing AWS, Azure or

11:52

Kubernetes, the workflow is identical.

11:55

If you want to begin your journey in

11:56

becoming a 10x engineer, I highly

11:58

recommend you check out Code Crafters

12:00

down below. And I believe they are the

12:02

best project-based coding platform out

12:04

there. Please subscribe if you enjoyed

12:06

and happy coding.

Interactive Summary

This video provides a comprehensive guide to Terraform, explaining how it enables infrastructure as code by allowing users to manage cloud resources through declarative configuration files rather than manual 'click-ops.' It details Terraform's core architecture—including the Terraform core, providers, and state management—and contrasts its immutable, provisioning-focused approach with configuration management tools like Ansible. The video also highlights the benefits of Terraform, such as its cloud-agnostic nature, version control capabilities, and large ecosystem.

Suggested questions

4 ready-made prompts