Working with terraform, lab: lifecycle rules # 11 -

This is the lab where you enable the lifecycle: create_before_destroy on a file. The file already exists with the same name and thus is not created because file names must be unique.

Why doesn’t Terraform check for this and throw an error?

Explanation from the lab:

Where did the file go?!!?

If you observe the output of the previous apply (scroll up!), you will see that the lifecycle rule we applied caused the local file to the created first and the same file to be destroyed during the recreate operation.

This goes to show that it is not always advisable to use this rule!

In this example, the filename argument for the local_file resource has to be unique which means that we cannot have two instances of the same file created at the same time!
The random_string resource on the other hand is a logical resource that is only recorded in the state and does not have such a restriction.

If you run terraform apply again, the file resource will be created as it does not exist currently.

As per terraform Documentation: Terraform is not the best solution to be used as A configuration management tool and they actually recommend using and configuration management tool when it comes to configuring the os itself in the instance or on the local OS.
so there are a lot of drawbacks to use terraform in any work that will be done on the OS of the machine.