Modules Using a Sub Module
Explore how to build and utilize Terraform submodules to set up two-way communication between multiple AWS security groups. Understand variable constraints and module nesting while creating concise and manageable infrastructure code.
Submodules
Modules can use modules inside themselves. We are going to go through an example of a three-way cross-talk module. The purpose of this module is to set up ingress and egress on a protocol and port of your choosing between three AWS security groups in both directions. To do this by hand would require twelve security group rules, but this can be shortened by using modules.
Project example
Let’s dive straight into the example. If you are following along with the course, create a folder in your workspace and add the following file structure:
Cross-talk folder
Let’s pause and discuss the cross-talk module that we have just defined.
variables.tf
Looking at the variables.tf, we have introduced a couple of new concepts. The first is that we are taking the whole ...