# netapp/terraform-provider-netapp-ontap architecture

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

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

## Overview

##### Project Type and Purpose
- This is an open-source Terraform provider plugin, written in Go, named “Terraform ONTAP Provider.”
- Purpose: Integrate Terraform (1.4+) with NetApp ONTAP resources by implementing data sources and resources for cluster, storage, networking, protocols, security, snapmirror, SVM, etc.

##### High-Level Architectural Components
a. Terraform Core / CLI
- The Terraform engine invokes the provider plugin via the Terraform Plugin SDK.
b. Provider Plugin (Go Binary)
- main.go: entry point that registers the provider with Terraform.
- internal/provider: implements all resource and data-source CRUD logic, organized by domain (cluster, storage, networking, protocols, security, snapmirror, svm, tag prefixes).
- internal/interfaces: defines abstract interfaces for each domain to decouple provider logic from REST client.
- internal/restclient:
- httpclient: generic HTTP client for sending REST calls to ONTAP APIs.
- awsclient: AWS Lambda client (used in certain workflows, e.g., FSx guides).
- internal/utils: common helpers (error handling, request formatting, etc.).
c. NetApp ONTAP Control Plane (External Service)
- The target ONTAP cluster’s management REST API endpoints.
d. Examples & Documentation
- examples/: Terraform configurations showing usage of data sources and resources.
- docs/: auto-generated and hand-written docs and guides.
e. CI/CD & Tooling
- GitHub Actions workflows (.github/workflows/): lint, unit‐test, build, security scanning (gosec, CodeQL), docs checks, release.
- GNUmakefile, scripts/: helper scripts for tests, doc generation, code scaffolding.
- goreleaser.yml: automated release packaging.
- terraform-registry-manifest.json: Terraform Registry integration.

##### Relationships and Data Flow
- User writes Terraform HCL → Terraform CLI
→ loads provider plugin (binary built from Go code)
→ plugin’s main.go registers schema & resource/data sources
→ Terraform applies plan → calls CRUD functions in internal/provider modules
→ provider logic invokes methods on internal/interfaces
→ interfaces implementations call internal/restclient to form HTTP requests
→ HTTPClient sends REST calls to the ONTAP cluster → receives JSON responses
→ data mapped back into Terraform state → returned to Terraform CLI → user.

##### Key Architectural Patterns and Principles
- Layered Architecture:
- Terraform Core
- Provider Plugin (entry point → domain logic → interfaces → REST client)
- External ONTAP API
- Clean Separation:
- internal/interfaces abstracts API operations (“contract-first” approach for testing).
- internal/provider contains business logic, resource/data-source definitions and tests.
- internal/restclient encapsulates HTTP/AWS interactions.
- Domain-Driven Modules: Each functional area (cluster, storage, networking, etc.) lives in its own package under internal/provider.

##### Detail and Coverage
- Dozens of resource/data-source packages implicitly under “Domain Logic” with an annotation “(e.g., internal/provider/storage, internal/provider/snapmirror, …)”.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Legend
    subgraph Legend
        L1["Terraform/Terraform SDK\n(color: blue)"]:::terraform
        L2["Provider Logic\n(color: green)"]:::provider
        L3["Interfaces/Abstractions\n(color: orange)"]:::interfaces
        L4["REST Client\n(color: red)"]:::rest
        L5["External Service\n(color: gray)"]:::external
    end

    %% Main Flow
    User["User (writes HCL)"]:::external
    CLI["Terraform CLI/Core"]:::terraform
    PluginEntry["main.go\n(Entry Point)"]:::terraform
    SchemaReg["provider.go\n(SDK Registration)"]:::terraform
    subgraph "Provider Plugin (Go Binary)"
        direction TB
        SchemaReg
        subgraph "Domain Logic" 
            direction TB
            Cluster["cluster\n(internal/provider/cluster)"]:::provider
            Storage["storage\n(internal/provider/storage)"]:::provider
            Networking["networking\n(internal/provider/networking)"]:::provider
            Protocols["protocols\n(internal/provider/protocols)"]:::provider
            Security["security\n(internal/provider/security)"]:::provider
            SnapMirror["snapmirror\n(internal/provider/snapmirror)"]:::provider
            SVM["svm\n(internal/provider/svm)"]:::provider
            NoteDomain["(...other domains)"]:::provider
        end
        Interfaces["Interfaces Layer\n(internal/interfaces)"]:::interfaces
        subgraph "REST Client"
            direction TB
            HTTP["HTTP Client\n(http_client.go)"]:::rest
            AWS["AWS Lambda Client\n(lambda_client.go)"]:::rest
            CoreRest["REST Core\n(rest_client.go)"]:::rest
        end
        Utils["Utilities\n(internal/utils)"]:::terraform
    end
    ONTAP["NetApp ONTAP API"]:::external

    %% Auxiliary Systems
    subgraph "Examples & Documentation"
        Examples["examples/"]:::external
        Docs["docs/"]:::external
    end

    subgraph "CI/CD & Tooling"
        Workflows[".github/workflows/"]:::external
        ReleaseCfg[".goreleaser.yml"]:::external
        MakeScripts["GNUmakefile\n& scripts/"]:::external
        Registry["terraform-registry-manifest.json"]:::external
    end

    %% Connections
    User -->|"runs plan"| CLI
    CLI -->|"loads plugin"| PluginEntry
    PluginEntry -->|"calls Register"| SchemaReg
    SchemaReg -->|"defines resources"| Cluster
    SchemaReg --> Cluster
    SchemaReg --> Storage
    SchemaReg --> Networking
    SchemaReg --> Protocols
    SchemaReg --> Security
    SchemaReg --> SnapMirror
    SchemaReg --> SVM

    Cluster -->|"Invoke Create()/Read()"| Interfaces
    Storage --> Interfaces
    Networking --> Interfaces
    Protocols --> Interfaces
    Security --> Interfaces
    SnapMirror --> Interfaces
    SVM --> Interfaces

    Interfaces -->|"Form REST calls"| CoreRest
    CoreRest --> HTTP
    CoreRest --> AWS

    HTTP -->|"HTTP GET/POST"| ONTAP
    AWS -->|"Invoke Lambda"| ONTAP

    Interfaces --> Utils
    SchemaReg --> Utils

    %% Aux connections
    Examples -.-> PluginEntry
    Docs -.-> PluginEntry
    Workflows -.-> PluginEntry
    ReleaseCfg -.-> PluginEntry
    MakeScripts -.-> PluginEntry
    Registry -.-> PluginEntry

    %% Click Events
    click PluginEntry "https://github.com/netapp/terraform-provider-netapp-ontap/blob/integration/main/main.go"
    click SchemaReg "https://github.com/netapp/terraform-provider-netapp-ontap/blob/integration/main/internal/provider/provider.go"
    click Cluster "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/provider/cluster"
    click Storage "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/provider/storage"
    click Networking "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/provider/networking"
    click Protocols "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/provider/protocols"
    click Security "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/provider/security"
    click SnapMirror "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/provider/snapmirror"
    click SVM "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/provider/svm"
    click Interfaces "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/interfaces"
    click HTTP "https://github.com/netapp/terraform-provider-netapp-ontap/blob/integration/main/internal/restclient/httpclient/http_client.go"
    click AWS "https://github.com/netapp/terraform-provider-netapp-ontap/blob/integration/main/internal/restclient/awsclient/lambda_client.go"
    click CoreRest "https://github.com/netapp/terraform-provider-netapp-ontap/blob/integration/main/internal/restclient/rest_client.go"
    click Utils "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/internal/utils"
    click Examples "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/examples/"
    click Docs "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/docs/"
    click Workflows "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/.github/workflows/"
    click ReleaseCfg "https://github.com/netapp/terraform-provider-netapp-ontap/blob/integration/main/.goreleaser.yml"
    click MakeScripts "https://github.com/netapp/terraform-provider-netapp-ontap/tree/integration/main/scripts/"
    click Registry "https://github.com/netapp/terraform-provider-netapp-ontap/blob/integration/main/terraform-registry-manifest.json"

    %% Styles
    classDef terraform fill:#cce5ff,stroke:#004085,color:#004085;
    classDef provider fill:#d4edda,stroke:#155724,color:#155724;
    classDef interfaces fill:#fff3cd,stroke:#856404,color:#856404;
    classDef rest fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
