WEBVTT - This file was automatically generated by VIMEO

0
00:00:00.300 --> 00:00:03.300
In this section, we will learn how to use modules from

1
00:00:03.300 --> 00:00:04.700
 the terraform registry.

2
00:00:07.200 --> 00:00:10.200
The modules we built in the last lecture is an example

3
00:00:10.200 --> 00:00:13.500
 of a local module given the fact that it resides within

4
00:00:13.500 --> 00:00:15.900
 the local machine better form is installed.

5
00:00:16.900 --> 00:00:19.300
As we discussed one of the advantages of

6
00:00:19.300 --> 00:00:22.300
 using modules is that it can be easily shared with others.

7
00:00:23.300 --> 00:00:26.200
Earlier in the lectures about providers. We saw that

8
00:00:26.200 --> 00:00:29.300
 the terraform registry is used to provide a plugins

9
00:00:29.300 --> 00:00:31.800
 such as the ones used by AWS.

10
00:00:32.500 --> 00:00:35.400
Besides the provider plugins. The registry is

11
00:00:35.400 --> 00:00:38.500
 also used as a public repository that stores

12
00:00:38.500 --> 00:00:38.900
 modules.

13
00:00:40.900 --> 00:00:43.400
The modules enter from registry are group

14
00:00:43.400 --> 00:00:46.600
 based on the provider for which they are created and they

15
00:00:46.600 --> 00:00:50.200
 are available for anyone to use to provision infrastructure. They

16
00:00:49.200 --> 00:00:52.900
 can be categorized into two types A verified

17
00:00:52.900 --> 00:00:54.600
 module and the community module.

18
00:00:55.400 --> 00:00:58.800
For example, if we search for a module for creating security

19
00:00:58.800 --> 00:01:01.200
 groups in AWS, there would be

20
00:01:01.200 --> 00:01:03.500
 quite a few matching results written back to us.

21
00:01:04.300 --> 00:01:07.400
Verified modules such as the AWS Security Group

22
00:01:07.400 --> 00:01:10.500
 modules here are tested and maintained by hashicorp and

23
00:01:10.500 --> 00:01:12.800
 have a blue Tech bar next to its name.

24
00:01:13.600 --> 00:01:16.500
The other modules that do not have this verified checkmark

25
00:01:16.500 --> 00:01:19.500
 have been published by users in the community, but they

26
00:01:19.500 --> 00:01:21.100
 are not validated by hashicorp.

27
00:01:23.100 --> 00:01:26.300
A terraform module that is available in the registry should

28
00:01:26.300 --> 00:01:29.500
 usually contain details about the module such as the publisher

29
00:01:29.500 --> 00:01:32.100
 information the different versions of the module that is

30
00:01:32.100 --> 00:01:35.300
 available in the registry and instructions on how to use the

31
00:01:35.300 --> 00:01:36.600
 module with examples.

32
00:01:37.400 --> 00:01:40.400
And in some cases like the verified Security Group

33
00:01:40.400 --> 00:01:43.500
 module the module also contains several sub modules

34
00:01:43.500 --> 00:01:45.200
 that can be used for different use cases.

35
00:01:46.500 --> 00:01:49.200
The sub modules in this example can be used to

36
00:01:49.200 --> 00:01:52.600
 create several predefined Security Group rules such as

37
00:01:52.600 --> 00:01:55.700
 the Ingress SSH on Port 22 or allow

38
00:01:55.700 --> 00:01:58.200
 inbound HTTP or https connection.

39
00:01:59.100 --> 00:02:02.200
To make use of this module in our configuration we can make

40
00:02:02.200 --> 00:02:04.400
 use of the module block that we have seen before.

41
00:02:05.100 --> 00:02:08.400
But the value for the source argument would change as the module

42
00:02:08.400 --> 00:02:09.300
 is no longer local.

43
00:02:10.600 --> 00:02:13.300
For example to create a security group that

44
00:02:13.300 --> 00:02:16.600
 allows inbound SSH we can create a configuration

45
00:02:16.600 --> 00:02:18.700
 with the SSH sub module like this.

46
00:02:25.500 --> 00:02:28.000
From the documentation for this submodule. We can

47
00:02:28.100 --> 00:02:31.600
 see that it requires three mandatory arguments the name

48
00:02:31.600 --> 00:02:34.300
 of the security group The VPC to create

49
00:02:34.300 --> 00:02:37.800
 it in and the Ingress cider blocks which accepts a

50
00:02:37.800 --> 00:02:40.700
 list of IP address ranges from which SSH is

51
00:02:40.700 --> 00:02:41.100
 to be allowed.

52
00:02:42.700 --> 00:02:45.400
In order to make use of this module we can either

53
00:02:45.400 --> 00:02:48.200
 run terraform in it or if the

54
00:02:48.200 --> 00:02:51.700
 provider plugins have already been downloaded in the configuration directory.

55
00:02:51.700 --> 00:02:54.500
 We can simply run the terraform get command that

56
00:02:54.500 --> 00:02:57.000
 will only download the module from the registry.

57
00:02:58.200 --> 00:03:01.200
It is usually a good idea to specify the version of the

58
00:03:01.200 --> 00:03:04.200
 module as there can be many revisions that are made

59
00:03:04.200 --> 00:03:05.500
 to each module over time.

60
00:03:06.300 --> 00:03:09.500
Not specifying the version will always download the latest

61
00:03:09.500 --> 00:03:11.500
 version of the module from the registry.

62
00:03:12.500 --> 00:03:15.300
This may have introduced changes to the way it works

63
00:03:15.300 --> 00:03:17.400
 which may not always be desirable.

64
00:03:18.500 --> 00:03:21.400
Finally to create the security group using this module.

65
00:03:21.400 --> 00:03:23.700
 We can run terraform plan and then apply.

66
00:03:25.300 --> 00:03:28.700
That's it for this lecture. Let's now head over to the Hands-On

67
00:03:28.700 --> 00:03:31.400
 labs and practice working with terraform modules.
