Remote State Management in Terraform via GCP/AWS

What is Terraform State, and How Terraform manages it?

When we configure or automate any resource terraform, create a state file where it stores all the changes. So that next time when we try to modify or destroy the resource. It must know what we already have.

Can 2 people change Terraform State simultaneously?

No, when we hit ‘terraform apply,’ the State file gets locked and can’t be modified at the same time. The next user has to wait till the first one completes. This is a Default Feature of Terraform.

Why Remote State Management?

By default, Terraform stores state locally in a file named terraform.tfstate.
When working in a team it gets difficult to manage the state as each user must make sure they always have the latest state data before running Terraform, and nobody else runs Terraform at the same time.

State Management on Google Cloud Storage:

  1. create a GSC bucket. Enable versioning to prevent loss.

Output Of Terraform Init when Backed Is Configured :

State Locked Output :

Google Cloud Storage :

Thanks For Reading 🙏

Connect With Me:
LinkedIn: Here

Tech. Explorer