In this section, we will learn how to use modules from
the terraform registry.
The modules we built in the last lecture is an example
of a local module given the fact that it resides within
the local machine better form is installed.
As we discussed one of the advantages of
using modules is that it can be easily shared with others.
Earlier in the lectures about providers. We saw that
the terraform registry is used to provide a plugins
such as the ones used by AWS.
Besides the provider plugins. The registry is
also used as a public repository that stores
modules.
The modules enter from registry are group
based on the provider for which they are created and they
are available for anyone to use to provision infrastructure. They
can be categorized into two types A verified
module and the community module.
For example, if we search for a module for creating security
groups in AWS, there would be
quite a few matching results written back to us.
Verified modules such as the AWS Security Group
modules here are tested and maintained by hashicorp and
have a blue Tech bar next to its name.
The other modules that do not have this verified checkmark
have been published by users in the community, but they
are not validated by hashicorp.
A terraform module that is available in the registry should
usually contain details about the module such as the publisher
information the different versions of the module that is
available in the registry and instructions on how to use the
module with examples.
And in some cases like the verified Security Group
module the module also contains several sub modules
that can be used for different use cases.
The sub modules in this example can be used to
create several predefined Security Group rules such as
the Ingress SSH on Port 22 or allow
inbound HTTP or https connection.
To make use of this module in our configuration we can make
use of the module block that we have seen before.
But the value for the source argument would change as the module
is no longer local.
For example to create a security group that
allows inbound SSH we can create a configuration
with the SSH sub module like this.
From the documentation for this submodule. We can
see that it requires three mandatory arguments the name
of the security group The VPC to create
it in and the Ingress cider blocks which accepts a
list of IP address ranges from which SSH is
to be allowed.
In order to make use of this module we can either
run terraform in it or if the
provider plugins have already been downloaded in the configuration directory.
We can simply run the terraform get command that
will only download the module from the registry.
It is usually a good idea to specify the version of the
module as there can be many revisions that are made
to each module over time.
Not specifying the version will always download the latest
version of the module from the registry.
This may have introduced changes to the way it works
which may not always be desirable.
Finally to create the security group using this module.
We can run terraform plan and then apply.
That's it for this lecture. Let's now head over to the Hands-On
labs and practice working with terraform modules.