How netapp/terraform-provider-netapp-ontap works
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, …)”.