terraform.tfstate:
Terraform stores information about your infrastructure in a state file.
This state file keeps track of resources created by your configuration and maps them to real-world resources.
When you run terraform apply or terraform destroy against your initialized configuration, Terraform writes metadata about your configuration to the state file and updates your infrastructure resources accordingly.
For example,
Using *.tf deploy an AWS EC2 (t2.micro)
The terraform.tfstate file will recode the AWS EC2 resouse is t2.micro.
I change the EC2 instance type manualy, from t2.micro change to t3.small.
When I enter command "terraform plan", plan will show "1 to change"
When I enter command "terraform apply", the AWS EC2 will change back to t2.micro.
Refresh modified infrastructure:
The terraform refresh command updates the state file when physical resources change outside of the Terraform workflow.
For example,
Using *.tf deploy an AWS EC2 (t2.micro)
The terraform.tfstate file will recode the AWS EC2 resouse is t2.micro.
I change the EC2 instance type manualy, from t2.micro change to t3.small.
When I enter command "terraform refresh" and go to check the terraform.tfstate file
The AWS EC2 will change back to t3.small in the terraform.tfstate file.
When I enter command "terraform plan", plan will show "No changes"
Reference:
1. Terraform Documentation:
2. Manage Resources in Terraform State
最初發表 / 最後更新: 2022.07.16 / 2022.07.16
0 comments:
張貼留言