I’m just wondering if anyone has advice around how best to have business logic interact with Terraform.
For example, let’s say you were building an on-premise server virtualization Terraform module. You need to select the gold image, network, and DNS domain used to provision the machine based on some customer inputs combined with some additional business logic.
Would it be best to implement that logic:
- completely outside of Terraform (just pass the desired information directly to Terraform)?
- with conditionals inside of a Terraform local value?
- with the External Data Source?
- by building a custom provider?
The answer really depends on what other systems and processes you have.
Where does that information come from & live? If it lives in another system it would generally be better to keep it there (rather than duplicating elsewhere and needing to have processes to keep the copy up to date), and fetch the information from it. That could be via a data source or equally using wrapper scripts (that set environment variables or create .tfvars files).
Alternatively if there isn’t somewhere else you could store that data only within the Terraform domain. How you structure that again depends on how you want to do things. One option is to have multiple git repositories, with one containing a module with the common code and then repos for each usage which just passes in values for those parameters.