Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What is Terraform Modules?

What is Terraform Modules?

In this deck, you will learn everything you need to know about terraform modules and how to import and manage your modules catalog.

Product used: https://www.brainboard.co/

Full video: https://www.youtube.com/watch?v=SgmmoRCmIa4&list=PLIuWze7quVLDSxJKDj3pRSqvmHAzQ_9vd&index=6

00:02:00 Welcome
00:03:32 Meet Chafik, CEO of Brainboard.co
00:05:00 Our goal at Brainboard
00:06:00 Terraform modules definition
00:20:00 Build your own modules
00:21:00 Azure
00:48:00 AWS
00:52:00 Best practices
00:56:00 Review some of the most used community modules
00:56:43 Lambda
01:00:30 AKS
01:04:00 Where to host your modules?
01:06:04 Challenges of maintaining modules within a team
01:09:00 Build your own modules’ catalog

Stephane Boghossian

April 27, 2023
Tweet

Other Decks in Programming

Transcript

  1. Our goal at Brainboard - Reduce the learning curve of

    the cloud. - Offer quality trainings by going deeper in the technology and making it simple.
  2. You will learn 1. Terraform modules definition 2. Build your

    own modules 3. Where to host your modules? 4. Review some of the most used community modules 5. Challenges of maintaining modules within a team 6. Best practices 7. Build your own modules’ catalog
  3. What is a module? Module = container of resources that

    are used together (like docker, but for the infra) “root” is always there. Terraform actions (plan, apply & destroy) show the resources of the module In the Terraform code, a module is like a resource. It is a black box.
  4. When Why use modules? 1. Why do you want to

    use modules? How will the module be used? 1. What do you want to package as a building block? Don’t get drunk of modules 🙄 too quickly, even Hashicorp recommends moderation. 📌 Using modules should reflect your maturity on IaC.
  5. Community vs Private modules Community modules are stack based grouping

    logic VPC, DB, VNET Maybe your company needs producer <> consumer model Packaged application with its own subnet but using shared VPC, DB Building blocks vs packaged stacks.
  6. Build your module 🏛 Keep in mind - When to

    use locals (internal, not exposed) & variables (exposed and part of the input of the module) - What are the required variables? Those which are not required, need to have default values. - The outputs you define are directly related to how the module will be used - The output of a module can be used as input to any other resource/module - You can nest outputs - Module can call another module(s) called child
  7. Module = cloud infrastructure Create Azure webapp module - 1

    module - Split into different modules - Use output between modules Landing zone in AWS Build your module 🏛
  8. Best practices - Keep modules small Tfstate refresh may suffer

    when the number of resources increase - Name output close to the original names of resources. For e.g. vpc_id - Avoid edge cases in modules - Start with a working MVP before moving up the stack - Think about how to maintain the module while building it
  9. Where to host your modules ☁️ The most used locations:

    - Terraform registry (you can use versions) - Git repository (even git::https or git::ssh) - Local path 😱 You can also use: - S3 bucket - Zip file over HTTP
  10. Manage your modules with your team 👨👩👧 - Don’t put

    so much magic in the modules - Explicit is better than implicit - Provide variables that are meaningful to the end user - Have a strategy about resource to create vs existing one to use - How to handle versioning. Pinning vs latest - Open to contribution by anyone - How to use only valid modules? - How to manage credential used to manage modules in the CI