WEBVTT

00:01.330 --> 00:02.470
In the previous lectures,

00:02.640 --> 00:05.610
we learned about
Terraform state and its benefits.

00:06.700 --> 00:08.860
Terraform state
is the single source of truth

00:09.030 --> 00:12.320
for a Terraform to understand
what is deployed in the real world.

00:12.930 --> 00:13.550
However,

00:13.710 --> 00:15.440
there are a few things
to keep note of

00:15.610 --> 00:16.870
when working with state,

00:17.040 --> 00:19.280
and we will learn about them
in this lecture.

00:20.320 --> 00:22.970
State is a non-optional feature
in Terraform.

00:23.440 --> 00:24.060
However,

00:24.230 --> 00:25.860
there are a few considerations.

00:26.910 --> 00:27.900
First one is that,

00:28.070 --> 00:30.860
the state file contains
sensitive information.

00:31.440 --> 00:31.980
Within it,

00:32.150 --> 00:35.340
it contains every little detail
about our infrastructure.

00:36.710 --> 00:38.770
Here is an example snippet
of a state file

00:38.940 --> 00:41.020
for an AWS EC2 instance

00:41.240 --> 00:44.500
which is, essentially,
a virtual machine on the AWS cloud.

00:45.470 --> 00:47.460
The state file consists
of all the attributes

00:47.630 --> 00:49.560
for a virtual machine
that is provisioned,

00:49.730 --> 00:52.300
such as the allocated CPUs,

00:52.470 --> 00:53.350
the memory,

00:53.520 --> 00:55.650
operating system, all the image used,

00:55.830 --> 00:57.870
type and size of disks, et cetera.

00:58.770 --> 01:00.080
It also stores information

01:00.250 --> 01:02.790
such as the IP address allocated
to the VM

01:02.930 --> 01:05.220
and the SSH keypad used, et cetera.

01:06.350 --> 01:08.300
For resources such as databases,

01:08.470 --> 01:11.010
the state may also store
initial passwords.

01:11.720 --> 01:13.060
When using local state,

01:13.230 --> 01:15.860
the state is stored
in plain-text JSON files.

01:16.290 --> 01:17.290
And as you can see,

01:17.450 --> 01:21.130
this information can be classified
as sensitive information.

01:22.050 --> 01:22.590
And as a result,

01:22.760 --> 01:24.260
we need to make sure
that the state file

01:24.420 --> 01:26.770
is always stored in a secure storage.

01:28.150 --> 01:28.610
So,

01:28.780 --> 01:31.950
we have two kinds of files
in our configuration directory.

01:32.260 --> 01:35.580
Data from state file, that stores
state of the infrastructure

01:35.790 --> 01:37.380
and data from configuration files

01:37.540 --> 01:40.400
that we use to provision
and manage infrastructure.

01:41.400 --> 01:42.780
When working as a team,

01:42.950 --> 01:44.310
it is considered a best practice

01:44.480 --> 01:46.350
to store
Terraform configuration files

01:46.520 --> 01:48.230
in distributed
version control systems,

01:48.400 --> 01:49.740
such as GitHub,

01:49.910 --> 01:51.420
GitLab, or Bitbucket.

01:52.060 --> 01:52.660
However,

01:52.820 --> 01:55.170
owing to the sensitive nature
of the state file,

01:55.340 --> 01:58.190
it is not recommended to store them
in Git repositories.

01:58.710 --> 01:59.340
Instead,

01:59.510 --> 02:01.690
store the state in
remote backend systems

02:01.840 --> 02:03.400
such as AWS S3,

02:03.560 --> 02:04.870
Google Cloud Storage,

02:05.030 --> 02:06.060
Azure Storage,

02:06.220 --> 02:07.640
Terraform Cloud, et cetera.

02:08.760 --> 02:11.190
We will see how to work
with remote state backends

02:11.360 --> 02:13.170
in a dedicated section of its own,

02:13.410 --> 02:14.020
but for now,

02:14.180 --> 02:16.990
it's important to make a note
of these considerations.

02:18.100 --> 02:20.320
Terraform state
is a JSON data structure

02:20.490 --> 02:23.210
that is meant for internal use
within Terraform.

02:23.910 --> 02:27.380
We should never manually attempt
to edit the state files ourselves.

02:28.050 --> 02:28.660
However,

02:28.830 --> 02:30.630
there would be situations
where we may want

02:30.800 --> 02:32.660
to make changes to the state file.

02:32.850 --> 02:33.820
And in such cases,

02:33.990 --> 02:36.210
we should rely on
terraform state commands.

02:36.720 --> 02:39.450
We will cover these
in a later section of the course.

