So, I’ve created a VPC in AWS, and I can log in etc, but I want generalise this as much as possible, so that I can define my infrastructure just once, and then change the provider with a parameter, ideally.
However, I don’t know terraform well enough yet, so I can’t quite see how to do this. Any suggestions?
Hi @j4nd3r53n,
Multi-vendor abstraction in Terraform operates at a higher level of abstraction that individual infrastructure objects. The main pattern for achieving it is module composition, which involves implementing the same concept once for each target platform as a module, and then including the appropriate module(s) in each configuration to select a specific implementation of each concept.
The idea of virtual networks is often not really productive to generalize as an abstraction, because each vendor implements their virtual network concepts slightly differently.
Instead, we usually generalize at a level of abstraction that relates to the higher-level problem you are solving. For example, you could write a set of Terraform modules that each create a Kubernetes cluster on a specific platform, exporting the resulting Kubernetes API endpoint, and then compose that with other modules that use the Kubernetes provider to interact with that API endpoint regardless of how it was created.
There is a simple example of this idea in the terraformdns
namespace in the Terraform Registry. Those modules are experimental at the time of writing, but they illustrate the idea of implementing the same functionality once per target platform while using a similar set of input variables and output values so that other components of the system can declare the DNS records they need without hard-coding a particular DNS vendor.