Sobes.tech
Junior — Middle

If you completely reset the resource state in Terraform and upload it to the cloud provider, how will this affect subsequent project initialization with the 'terraform init' command?

sobes.tech AI

Answer from AI

If you completely reset the resource state (the terraform.tfstate file) and then upload the configuration to the cloud provider, the terraform init command by itself will not change the project state, as it only initializes the working directory and loads providers.

However, when running terraform apply afterwards, Terraform will detect that resources present in the cloud are missing from the local state and will attempt to recreate them, which could lead to resource duplication or conflicts.

To properly synchronize the state after a reset, you should use the terraform import command to attach existing resources to the state, or restore the state file from a backup.

Thus, terraform init does not depend on the resource state, but resetting the state requires additional steps for correct infrastructure management.