Well-Architected Framework
Create reusable infrastructure modules
If you repeatedly provision the same group of resources, you can refactor your configuration to use reusable collections instead. Reusable collections of components reduce the time it takes to deploy infrastructure by allowing developers to reuse configuration instead of writing it from scratch. Developers can also design reusable collections to comply with organizational best practices and security guidelines.
Create Terraform modules
A Terraform module is a set of Terraform configuration files in a single directory. Modules are reusable and customizable; you can wrap modules with configurations to fit your organization's standards. Creating a more modular infrastructure encourages your organization to decouple services by helping you focus on logically related resources. Decoupling can reduce the scope of failure and enable more efficient deployment due to reduced system dependencies.
For example, if your team manages object storage for multiple applications that all follow your organization's common standards, such as security or lifecycle management, you can use an object storage Terraform module for your cloud providers. The object storage module can contain configuration such as lifecycle policies or security standards. You can store and version the module in a version control repository or Terraform registry and share it across your organization for developers to access.
Use the Terraform Registry
The Terraform Registry is a single source for finding providers and their supporting documentation. You can find official, partner, and community providers, modules, policy libraries, and run tasks in the Terraform Registry. The Terraform Registry is a great first step in learning all the resources you can manage with Terraform.
You can find publicly available Terraform modules for configuring many kinds of common infrastructure in the Terraform Registry. These modules are free to use, and Terraform can download them automatically if you specify the appropriate source and version in a module call block.
Your organization may produce modules tailored for your own infrastructure needs. HCP Terraform and Terraform Enterprise both include a private module registry for sharing modules internally within your organization.
Next steps
In this section of Define your processes, you learned about using Terraform modules to standardize your infrastructure deployments. Create reusable infrastructure modules is part of the Define and automate processes pillar.
Refer to the following documents to learn more about infrastructure definition:
- Define infrastructure as code to understand infrastructure as code principles
- Topics in Automate your workflows
- CI/CD - Implement automation for infrastructure and applications
- Testing - Implement testing for infrastructure and applications
- Deployment - Implement deployment for infrastructure and applications
- Packaging - Package applications for deployment
If you are interested in learning more about Terraform modules, you can check out the following resources:
- Terraform module registry - Browse available Terraform modules
- Learn how to create Terraform modules - Create your own modules
- Learn how to reuse configuration with modules - Use modules in your configurations