Construct class, you can group multiple resources together into a single, reusable component. This allows you to encapsulate complex infrastructure patterns and share them across projects.
Extending the Construct Class
To create a custom construct, define a class that extendsConstruct.
Parameterized Infrastructure
By passing aprops object to the constructor, you can make your construct configurable. This allows you to reuse the same logic for different environments or use cases.
Composition Patterns
Constructs can be composed of other constructs, allowing you to build deep hierarchies of infrastructure.Best Practices
- Encapsulation: Keep internal resources private or protected unless they need to be accessed from outside the construct.
- Naming: Use descriptive IDs for child resources. tfts will automatically prefix these IDs with the construct’s ID to ensure uniqueness in the Terraform configuration.
- Validation: You can add validation logic inside the constructor to ensure that the provided properties are valid before synthesis.
- Defaults: Provide sensible default values for optional properties to make your construct easier to use.