terraform vs dsl

October 16, 2024

Data Mesh Terraform DSL

When Terraform Turns Terraterror, or About Why DSL Beats Custom Terraform Scripts

In today's data-driven organizations, especially those embracing the principles of the data mesh architecture, flexibility is on every manager’s PP presentation. The need for scalable, adaptable, and autonomous infrastructure is at an all-time high.

Enters Terraform, the widely adopted tool for Infrastructure as Code (IaC) & all our needs were addressed. Or, were they?

While Terraform is undoubtedly powerful, there is a growing debate on whether its role as a central tool in complex ecosystems might be better replaced—or complemented—by Domain-Specific Languages (DSLs).

Let's explore why leveraging DSLs for resource provisioning could offer advantages over drowning in custom Terraform scripts, especially in the context of data platforms.

The Data Mesh and Infrastructure Complexity

Data Mesh Referential Architecture

In a data mesh setup, much like in the case of other modern ideas changing the world of tech, decentralization is the core philosophy.

Teams are empowered to own their data products, with self-serve platforms providing them the autonomy they need to handle lifecycle management, integrations, and cross-domain data sharing. However, this freedom comes with its own challenges. For teams to manage their products effectively, they need an abstraction layer that shields them from the intricate details of the underlying infrastructure.

In a nutshell, the holy grail here is to enable teams to manage their data products without becoming infrastructure experts.

And while Terraform provides an infrastructure-as-code approach, the sheer volume of custom scripts required to manage diverse environments like Google Cloud Platform (GCP), Snowflake, and orchestration tools like Cloud Composer often becomes burdensome.

Terraform's Potential Pitfalls: Custom Code Overload

Data Mesh With Vanilla Terraform

Terraform excels at declaratively defining and provisioning cloud resources. But as the complexity of the infrastructure scales, so does the complexity of the Terraform scripts.

Thus, we’ve seen many times teams spending more time managing Terraform configurations than focusing on delivering value from their data products. And it’s not because of Terraform itself, it’s just the nail to hammer is sometimes a tad too big.

Simply put, when you layer in complex integrations with services like GCP, Snowflake, and fully orchestrated pipelines, custom Terraform code can quickly become overwhelming.

While Terraform offers modularity and reusability through modules, this can still result in vast amounts of code—particularly when accommodating unique environments and specific needs of multiple domains. Managing, maintaining, and debugging this vast array of scripts soon becomes a pain point.

When teams need to focus on their core data product work, maintaining large amounts of custom Terraform code can slow them down, create bottlenecks, and introduce the risk of human error.

The Promise of DSL: Simplification and Abstraction

The beauty of a higher-level Domain-Specific Language (DSL) lies in its abstraction capabilities. Rather than defining infrastructure in Vanilla Terraform, a DSL presents an easier, more streamlined way to provision resources. For example, in the case of our setup, an orchestrated pipeline integrated with a DSL automates the resource provisioning for GCP and Snowflake, effectively eliminating the need for custom Terraform scripts.

Ultimately, the DSL serves as a high-level abstraction, but behind the scenes, it is eventually translated into Terraform. While the initial setup takes some extra effort spent on conversion, the generated Terraform code is solid and well-tested, so the data teams don’t need to worry about the underlying complexity.

With this approach, teams are no longer required to develop and manage custom Terraform code for every new resource or environment. Instead, the DSL simplifies the most common provisioning tasks into readable, maintainable commands tailored to their needs. This not only speeds up the process but also ensures that the infrastructure follows best practices out of the box.

Moreover, integrating this DSL with a Continuous Integration/Continuous Deployment (CI/CD) pipeline further streamlines the workflow. The teams can focus on building their data products while the infrastructure pieces fall into place automatically. In this sense, the DSL transforms infrastructure management from a complex, time-consuming task into a simplified, automated process that can be handled efficiently, even by non-infrastructure experts.

Data Mesh With DSL-Driven Infrastructure

Cross-Domain Access and Integration

Another significant advantage of leveraging a DSL in a data mesh architecture is the ease of cross-domain data product access and integration. When each team is using a common, streamlined language to provision resources, the complexity of interacting with resources managed by other domains diminishes.

This fosters collaboration and promotes seamless data product querying and integration across domains, which is crucial in a data mesh architecture. The platform can also monitor and document these interactions, ensuring that teams have visibility into how their data products are being used in the broader ecosystem.

Terraform as a Tool, Not the Solution

This is not to say that Terraform doesn’t have its place—it absolutely does. However, it should be viewed as one tool in a broader toolkit rather than the sole solution for managing infrastructure. By leaning heavily on a DSL for common provisioning tasks, teams can avoid being bogged down by the intricate details that Terraform often requires.

The Initial Effort of Defining Components and Parameters

For the record: before teams can fully leverage the benefits of a DSL, there is a significant upfront effort required. It's crucial to first define all available components and parameters that the product teams will be working with. This step is critical to ensure that teams know exactly what resources and infrastructure they can create, making the self-serve model effective.

While this initial setup can be time-consuming and requires careful planning, it pays off in the long run. By clearly specifying the available infrastructure components, teams are empowered with the knowledge and tools they need to manage their own data products efficiently. Although this setup phase can be resource-intensive, it's a foundational investment that enables scalability and autonomy across the organization.

DSL over Terraform Custom Code

So, Terraform or Terraterror? The answer lies in understanding the context in which your teams operate. For organizations embracing the data mesh paradigm, where decentralization, autonomy, and flexibility are key, a DSL can offer a more efficient, user-friendly, and scalable way to manage infrastructure than the labyrinth of custom Terraform scripts. By abstracting away the complexity and reducing the burden of infrastructure management, a DSL empowers teams to focus on what matters most: building and improving their data products.

High time to reconsider the role Terraform plays in modern data teams? You decide, but for sure do yourself a favor & explore the advantages of DSLs in a world where infrastructure management should enable, not hinder, innovation.