# databricks/terraform-provider-databricks architecture

> Architecture diagram of the GitHub repository databricks/terraform-provider-databricks, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/databricks/terraform-provider-databricks
- Repository: https://github.com/databricks/terraform-provider-databricks

## Overview

This project is the Databricks Terraform Provider—a Go-based Terraform plugin that enables users to provision and manage Databricks resources via Terraform. The provider implements a large set of resources and data sources (e.g., clusters, catalog, jobs, SQL endpoints, workspaces, etc.) and uses a modular, plugin-driven design.

##### Main Components
- Terraform Engine & Provider: Show Terraform as the orchestration engine that loads the Databricks provider plugin. Emphasize that the provider acts as a plugin that implements the Terraform Resource and Data Source interfaces.
- Provider Core: Illustrate the main “provider” binary (main.go and go.mod), which bootstraps the plugin.
- Resource & Data Modules: Group directories like catalog, clusters, access, dashboards, jobs, mlflow, mws, pipelines, and others under “Resources & Data Sources.” Indicate that each of these modules encapsulates the logic for managing a specific Databricks feature.
- Plugin Framework & Internal Providers: Represent the “internal/providers” and “internal/providers/pluginfw” directories as components that implement the extensible plugin framework. They handle tasks including auto-generation, attribute conversion, and mapping between Terraform schema and Databricks API models.
- Exporter Module: Mark the “exporter” component as an experimental sub-system (which provides an evolving interface to export or generate Terraform configurations from Databricks resources).
- Testing and CI/CD: Optionally include elements for integration and acceptance tests (directories like “internal/acceptance” and GitHub workflows). These illustrate how the project ensures quality and compliance via automation.

##### Depicting Relationships and Data Flow
- For each resource or data module, illustrate a flow that begins at the provider core, then delegated to the specific module (e.g., clusters, notebooks, etc.), and then outward through HTTP or API calls to the Databricks cloud.
- Bidirectional communication (request/response) with the external Databricks API.
- Internal plugin framework as a mediator that handles schema conversions, resource mapping, and, in some cases, automatic generation of resource code—pointing to the corresponding “internal/providers/pluginfw” modules.

##### Architectural Patterns & Design Principles
- Modularity: Emphasize that each functional domain (access, catalog, clusters, etc.) is separated into its own directory/module, making the system highly modular.
- Plugin Architecture: Show how the internal plugin framework provides extensibility. Each resource product (e.g., “app”, “cluster”, “mlflow”, “jobs”, etc.) is implemented as a separate plugin component that adheres to a common interface.
- Code Generation: Note the presence of the codegen components (e.g., .codegen.json, codegen directory) which help automate parts of the implementation.
- Test-Driven: Illustrate that there is a robust set of unit, integration, and acceptance tests to validate each component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    TE["Terraform Engine"]:::engine

    subgraph "Provider Core"
        PC1["Provider Core"]:::core
        PG1["main.go"]:::core
        PG2["go.mod"]:::core
        PC1 -->|"uses"| PG1
        PC1 -->|"uses"| PG2
    end

    TE -->|"loads"| PC1

    subgraph "Resource Modules"
        RM1["Catalog"]:::resource
        RM2["Clusters"]:::resource
        RM3["Access"]:::resource
        RM4["Dashboards"]:::resource
        RM5["Jobs"]:::resource
        RM6["MLflow"]:::resource
        RM7["MWS"]:::resource
        RM8["Pipelines"]:::resource
        RM9["Apps"]:::resource
        RM10["AWS"]:::resource
    end

    PC1 -->|"delegates"| RM1
    PC1 -->|"delegates"| RM2
    PC1 -->|"delegates"| RM3
    PC1 -->|"delegates"| RM4
    PC1 -->|"delegates"| RM5
    PC1 -->|"delegates"| RM6
    PC1 -->|"delegates"| RM7
    PC1 -->|"delegates"| RM8
    PC1 -->|"delegates"| RM9
    PC1 -->|"delegates"| RM10

    subgraph "Plugin Framework"
        PF1["internal/providers"]:::plugin
        PF2["internal/providers/pluginfw"]:::plugin
        PF1 -->|"extends"| PF2
    end

    PC1 -->|"integrates"| PF1

    EXPR["Exporter"]:::core
    PC1 -->|"experimental_export"| EXPR

    API["Databricks Cloud API"]:::external
    RM1 -->|"calls"| API
    RM2 -->|"calls"| API
    RM3 -->|"calls"| API
    RM4 -->|"calls"| API
    RM5 -->|"calls"| API
    RM6 -->|"calls"| API
    RM7 -->|"calls"| API
    RM8 -->|"calls"| API
    RM9 -->|"calls"| API
    RM10 -->|"calls"| API

    subgraph "Testing & CI/CD"
        TEST1["Acceptance Tests"]:::test
        TEST2["CI/CD Workflows"]:::test
        TEST1 -->|"triggers"| TEST2
    end

    PC1 -->|"validated_by"| TEST1

    click PG1 "https://github.com/databricks/terraform-provider-databricks/blob/main/main.go"
    click PG2 "https://github.com/databricks/terraform-provider-databricks/blob/main/go.mod"
    click RM1 "https://github.com/databricks/terraform-provider-databricks/tree/main/catalog/"
    click RM2 "https://github.com/databricks/terraform-provider-databricks/tree/main/clusters/"
    click RM3 "https://github.com/databricks/terraform-provider-databricks/tree/main/access/"
    click RM4 "https://github.com/databricks/terraform-provider-databricks/tree/main/dashboards/"
    click RM5 "https://github.com/databricks/terraform-provider-databricks/tree/main/jobs/"
    click RM6 "https://github.com/databricks/terraform-provider-databricks/tree/main/mlflow/"
    click RM7 "https://github.com/databricks/terraform-provider-databricks/tree/main/mws/"
    click RM8 "https://github.com/databricks/terraform-provider-databricks/tree/main/pipelines/"
    click RM9 "https://github.com/databricks/terraform-provider-databricks/tree/main/apps/"
    click RM10 "https://github.com/databricks/terraform-provider-databricks/tree/main/aws/"
    click PF1 "https://github.com/databricks/terraform-provider-databricks/tree/main/internal/providers/"
    click PF2 "https://github.com/databricks/terraform-provider-databricks/tree/main/internal/providers/pluginfw/"
    click EXPR "https://github.com/databricks/terraform-provider-databricks/tree/main/exporter/"
    click TEST1 "https://github.com/databricks/terraform-provider-databricks/tree/main/internal/acceptance/"
    click TEST2 "https://github.com/databricks/terraform-provider-databricks/tree/main/.github/workflows/"

    classDef engine fill:#87ceeb,stroke:#333,stroke-width:2px,color:#fff;
    classDef core fill:#ffa07a,stroke:#333,stroke-width:2px,color:#000;
    classDef resource fill:#90ee90,stroke:#333,stroke-width:2px,color:#000;
    classDef plugin fill:#d3d3d3,stroke:#333,stroke-width:2px,color:#000;
    classDef external fill:#f08080,stroke:#333,stroke-width:2px,color:#000;
    classDef test fill:#eee8aa,stroke:#333,stroke-width:2px,color:#000;
```
