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
recreateoperation.This goes to show that it is not always advisable to use this rule!
In this example, the
filenameargument for thelocal_fileresource has to be unique which means that we cannot have two instances of the same file created at the same time!
Therandom_stringresource 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 applyagain, thefileresource will becreatedas it does not exist currently.