Time
2 hours 48 minutes
Difficulty
Intermediate
CEU/CPE
3

Video Transcription

00:01
welcome to Module 4.5. We will be discussing terra form state files in this particular module. So I've gone ahead, and I've opened up the get hub page for this training course and specifically drilled into the 05 directory
00:16
and you'll notice we have a link here to the terra form state file documentation on terra form dot io.
00:23
I'm gonna give that a second and open it up and explain what a state files purposes and when it's all about,
00:29
um, as you can see, here and again, the terra form documentation itself is is really good and thorough. Um,
00:37
but if you can imagine, we have the terra form files which are declaring an infrastructure that needs to take place in the cloud.
00:46
And then you have how that infrastructure is
00:50
created. In fact, in the various cloud providers, for example, we are saying we wanna have a virtual network. We want to put a virtual machine on that network, want that virtual machine to have
01:02
two gigabytes of memory, right?
01:03
And then you have this circumstance, though where somebody could going through, say, the is er portal with web make changes to how that machine is defined, the amount of memory they can go in through the Web. You I, and change it to three gigabytes of memory. Um,
01:22
and tear form would really be none the wiser.
01:25
Um, and and that's that's really not good, because then when you're coming back and you have your terra form file and you're declaring that the machine should be two gigabytes of memory and then you run it, you really want to have good confidence that indeed the machine is two gigabytes of memory in is aligned with the terra form speck that you've declared.
01:42
So one is it's a bad practice to be doing some of the work in terra form and then
01:48
coming back and making changes after the fact through another mechanism outside of terra form. But what terra form does to try to reconcile the reality that that does happen, it can be a problem is it has a state file. So this is where it keeps track of the metadata
02:04
on DNA mapping between the real world. Resource is what is that virtual machine that actually got created
02:08
the first time you ran terra form apply.
02:12
What is the idea of that virtual machine and mapping those to the configuration s O. The next time you run the terror form application in and apply your terra form script, it's going to not create yet another virtual machine. It recognizes. I already created that virtual machine, and it's
02:30
matching these particular specs. And this is the idea of that virtual machine as it sits out, and
02:36
azar or AWS or something of that nature.
02:39
So the state file does get synchronized when you first bite by default with terra form. When it's creating the plan or putting the three apply, the state filed by default has been residing on your local workstation. What we want to talk about here is, if we're in a larger group
02:58
type situation, we don't want to each have our own state files on our own work stations. Because even though it does synchronize things, um,
03:09
it can get out of sync if, say, multiple people are applying updates to the infrastructure. Concurrently, right? One person kicks off their update and it's gonna run for five minutes, and then another person makes other changes to the infrastructure, and then they decide they want to kick that off about one minute
03:27
into that five minute deployment that the infrastructure
03:30
individual A had already started. That's gonna create a problem. So having a remote shared state will speed up the amount of time that Terra Form spends recalculating and re validating the state file. In fact, when you get really large infrastructures, you will by default, you we want to turn off that
03:50
default behavior of sinking the
03:52
the State Files because it's gonna
03:54
be it's gonna add a lot of overhead in terms of time because the amount of information being sink is gonna continue to grow and grow more over. You're gonna wanna be able thio work across your team and leverage locking so that no two people are performing terra form deployments into the same environment at the same time.
04:14
So these are the things we're going to go into. I also want to note that there are is information in these terra form state files like passwords and keys, and it's not encrypted. So what we're going to do in this lab is we're going to set up a shared storage container in azar itself
04:33
that's gonna be used
04:34
to host these terror form state files,
04:39
and we also when we're doing it, we want to make sure that the security constraints around who can access this state file are also there. So nobody can go poking in and read potentially some secrets out of that file. This is a known shortcoming that this information's there in planes text right, the secrets and keys and so forth. So
04:59
we want to make sure when we set up the storage container that the individuals and scope of access to this read access in particular is minimal. And then, of course, read right access. We want that to be limited to just those individuals that should be performing, deploys and using and contributing to this state file.

Up Next

Fundamentals of Terraform

In this Terraform training course, students will learn the basics of the tool through hands-on labs, become comfortable with its core language features, learn how Terraform fits into the cloud tooling landscape.

Instructed By

Instructor Profile Image
James Leone
Cloud, IoT & DevSecOps at Abbott
Instructor