Terraform Scenarios: A Good Starting Point!
??? Wanna share my understanding of Terraform!
Terraform is a powerful Infrastructure as Code (IaC) tool that helps automate resource provisioning. One of its key components is the state file, which plays a crucial role in managing infrastructure
1.What is the Terraform State File?
The Terraform state file (terraform.tfstate) stores metadata about the resources Terraform has created.
?? It tracks real-world resources and maps them to the configuration. ?? Terraform relies on this file to determine what exists and decide what to create, update, or delete.
2.How Terraform Works with the State File?
When you run terraform plan, Terraform performs the following actions:
? Reads the current state from terraform.tfstate. ? Queries the real infrastructure (actual state) to detect any unexpected changes. ? Compares it with the desired configuration in .tf files. ? Suggests changes to align the current state with the desired state.
Terraform always ensures that the current state matches the desired state.
领英推荐
3.What Happens if a Resource is Manually Modified?
Terraform does not automatically detect manual changes unless you run terraform plan.
?? terraform plan compares: ?? State file (recorded state) vs. Actual Infrastructure (real state). ?? If there’s a mismatch, Terraform suggests updates to align with the .tf configuration.
?? Example: If an EC2 instance type was manually changed from t2.micro to t3.micro, Terraform will detect this change and suggest reverting it back to t2.micro (if that’s what’s defined in the .tf file).
4.What Happens if a Resource is Manually Deleted?
If a resource exists in terraform.tfstate but is missing from the cloud provider:
? terraform plan detects that it no longer exists. ? Terraform will recreate the resource to match the .tf configuration.
5.What Happens if a Resource Exists in the Cloud but Not in the State File?
If Terraform doesn’t find a resource in terraform.tfstate, it assumes the resource does not exist and may try to create a new one.This can cause duplicate resources
? Discussion Question: What happens if your EC2 instance’s security group parameter wasn’t created by a Terraform resource? If you change the security group manually, will Terraform detect it as a change?
Electronics and Communication Engineer
3 周I really enjoyed reading your post. Add simple flow and logic diagrams and code snippets for intuitive understanding. keep up the good work!