In the previous lectures,
we learned about Terraform state and its benefits.
Terraform state is the single source of truth
for a Terraform to understand what is deployed in the real world.
However,
there are a few things to keep note of
when working with state,
and we will learn about them in this lecture.
State is a non-optional feature in Terraform.
However,
there are a few considerations.
First one is that,
the state file contains sensitive information.
Within it,
it contains every little detail about our infrastructure.
Here is an example snippet of a state file
for an AWS EC2 instance
which is, essentially, a virtual machine on the AWS cloud.
The state file consists of all the attributes
for a virtual machine that is provisioned,
such as the allocated CPUs,
the memory,
operating system, all the image used,
type and size of disks, et cetera.
It also stores information
such as the IP address allocated to the VM
and the SSH keypad used, et cetera.
For resources such as databases,
the state may also store initial passwords.
When using local state,
the state is stored in plain-text JSON files.
And as you can see,
this information can be classified as sensitive information.
And as a result,
we need to make sure that the state file
is always stored in a secure storage.
So,
we have two kinds of files in our configuration directory.
Data from state file, that stores state of the infrastructure
and data from configuration files
that we use to provision and manage infrastructure.
When working as a team,
it is considered a best practice
to store Terraform configuration files
in distributed version control systems,
such as GitHub,
GitLab, or Bitbucket.
However,
owing to the sensitive nature of the state file,
it is not recommended to store them in Git repositories.
Instead,
store the state in remote backend systems
such as AWS S3,
Google Cloud Storage,
Azure Storage,
Terraform Cloud, et cetera.
We will see how to work with remote state backends
in a dedicated section of its own,
but for now,
it's important to make a note of these considerations.
Terraform state is a JSON data structure
that is meant for internal use within Terraform.
We should never manually attempt to edit the state files ourselves.
However,
there would be situations where we may want
to make changes to the state file.
And in such cases,
we should rely on terraform state commands.
We will cover these in a later section of the course.