4
Writing Reusable Code Using Modules
One of the main objectives of Infrastructure as Code (IaC) is to create reusable code using the Don’t Repeat Yourself (DRY) software principle. Andrew Hunt and David Thomas first formulated this principle (Hunt, Andrew; Thomas, David (1999). The Pragmatic Programmer: From Journeyman to Master (1 ed.). USA: Addison-Wesley. pp. 320. ISBN 978-0201616224). In essence, it states that we should avoid repeating code.
In functional programming languages, we use functions to keep our code DRY. In Terraform, we use modules. In this chapter, we will start by outlining the basic structure of a module and then see how to write flexible modules that will be useful to others in our organization or the community at large. ...
Get Terraform for Google Cloud Essential Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.