Null Resources
We'll learn about null resources and how they work.
We'll cover the following
null_resource
#
A null_resource
is a special no-op resource that creates nothing. It is a dummy resource that allows
you to attach a provisioner to it. This resource should be avoided unless necessary.
Project Example#
Let’s look at an example. If you want to use a null_resource
to run the script that sets up the nginx server we have been running, that would look like:
To get this to work, though, you would have to put a delay into the script, otherwise, it will
try to run the command before the server is ready to accept SSH connections. You would never use a null_resource
for this. As we have explained, you would use user_data
to configure an instance upon startup.
null_resource
usability#
I wanted to include the null_resource
for completeness, but the fact that I could not come up with
a good example of when to use it shows how rarely they are useful in the real world.