I originally posted this to Reddit w/ the same title Best practices for non-cloud resource or data-only Terraform modules, but I think this is the right place to repost it too.
I’m looking for ways and ideas to develop a Terraform module which does not create any resources on cloud or any resources in local environment like files, but a module that generates some data or metadata, based on an input data.
For example, let’s say I need to capture a concept of a customer for which I need to generate some data or metadata and bundle those together as output and pass over as input read by other modules.
Something like this:
-
A customer module takes a customer name and basic details about required AKS node(s) , then generates customer identifier, customer tags, digests AKS node requirements into more complete descriptor. Such module could make up a “customers metadata stack”. The important issue is that this module would not deploy any provider-based cloud resources. It would only create things like
terraform_data
,random_id
, etc. So, although those feature do create actual Terraform resources, for this project I’d rather consider them as primitives, values, used similarly as in object value pattern in Domain-Driven Design. -
A cluster module is given the customer module output and turns it into AKS nodes(s) deployment that is provisioned, named and tagged according to what the customer module generated. This module would be part of the “customers platform stack”.
Although the part 2. is clear and simple yet typical Terraform module creating real on cloud resource with azurerm_kubernetes_cluster
and azurerm_kubernetes_cluster_node_pool
, the part 1. is not as clear and I have number of questions.
- Does this idea make sense or am I trying to bend Terraform in ways it was not meant to be?
- What other Terraform features apart from terraform_data, random_id are available for such data and metadata ‘values’?
- What other suggestions would you have for such data/value-only module?
- Do you know any Terraform modules which are good examples for data/value-only modules?