Terraform is a versatile tool that supports a wide array of providers. When most people think of Terraform, they often associate it with the big three cloud providers: AWS, Azure, and GCP. Admittedly, I’ve contributed to this mindset. In my book, Mastering Terraform, I cover these three clouds extensively and equally. However, the reality is that Terraform’s capabilities extend far beyond these giants. With its provider ecosystem, anything with an API can be managed through Terraform. The key lies in having the right provider.

Providers come in two flavors: official and community. Official providers are built and maintained by HashiCorp or the companies that own the platform, such as IBM Cloud and Datadog. On the other hand, community providers are developed by enthusiasts like you and me. These providers are a testament to Terraform’s open and flexible ecosystem. Some of my personal favorites are community providers, such as the Minecraft provider and the Proxmox provider.

For this article, we’ll explore how to manage the database schema for Azure Data Explorer (ADX) using the community provider favoretti/adx.

Choosing the Right Community Provider

When working with platforms that lack an official provider, you’ll often encounter multiple community providers for the same platform. This isn’t necessarily a bad thing. Each provider is typically born from a unique need or perspective. Maybe the developers were unaware of an existing provider, or perhaps they wanted features tailored to their use case. These providers are usually labors of love, written in spare time out of personal interest or for the sheer accomplishment.

However, this abundance of choices means you may need to evaluate different providers before settling on one. Consider factors like feature set, maturity, and activity level. If a provider is actively maintained, it might be a better choice than one with slightly more features but a long history of stagnation.

In my case, I selected favoretti/adx based on its features and perceived maturity. My goal was simple: automate my ADX clusters without investing time in contributing to the provider itself.

Setting Up the ADX Provider

To get started, you’ll need to configure Terraform to use both the AzureRM provider and the ADX provider. Below is an example of how to declare these providers in your Terraform configuration:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.54.0"
    }
    adx = {
      source  = "favoretti/adx"
      version = "~> 0.0.21"
    }
  }
  backend "azurerm" {
  }
}

Here, we specify the required versions for both providers. Ensure that you’ve provisioned your ADX cluster using the AzureRM provider before proceeding.

Authenticating with the ADX Provider

Authentication is a crucial step in setting up the ADX provider. You’ll need the URL of your ADX cluster, which you likely provisioned using the AzureRM provider. I recommend passing this value as an input variable. It’s not sensitive information and ensures flexibility if authentication requirements change in the future.

provider "adx" {
  adx_endpoint = var.adx_cluster_uri
}

For the authentication context itself, use environment variables instead of hardcoding sensitive information. The ADX provider supports only client secret-based authentication, so you’ll need to provide the following environment variables:

  • ADX_CLIENT_ID: The client ID of your service principal in Azure AD.
  • ADX_CLIENT_SECRET: The client secret of your service principal.
  • ADX_TENANT_ID: The tenant ID of your Azure AD instance.

Setting these as environment variables ensures that sensitive data stays out of your Terraform configuration files, enhancing security and maintainability.

Wrapping Up

Once you’ve configured the provider and set up authentication, you’re ready to manage your ADX schema with Terraform. The flexibility of Terraform’s provider ecosystem, combined with community contributions like favoretti/adx, makes it possible to automate even niche platforms like Azure Data Explorer.

As with any community provider, remember to stay aware of updates and changes, as they’re often maintained by dedicated individuals in their spare time. By leveraging Terraform’s power, you can simplify your infrastructure management and focus on building solutions rather than manually configuring resources.