# n3integration/terraform-provider-godaddy architecture

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

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

## Overview

##### Project Type and Purpose
- This is a Terraform provider plugin written in Go.
- It implements the Terraform Plugin Protocol, exposing a `godaddy_domain_record` resource to manage GoDaddy DNS records via their REST API.

##### File Structure
- Top-level:
- `main.go` – entrypoint registering the plugin with Terraform.
- `plugin/godaddy/` – provider implementation (config, schema, resource logic).
- `api/` – standalone GoDaddy API client and domain-record types.
- `docker/` – Dockerfile and compose for local testing/integration.
- `docs/` – user-facing documentation and examples.
- Tests: integration and unit tests live alongside code (`*_test.go`).
- CI/CD: GitHub Actions (`.github/workflows/release.yml`), GoReleaser config.

##### Extract Key Architecture Insights from the README
- Uses environment variables or in-Terraform credentials for GoDaddy API key/secret.
- Exposes provider block and a single resource: `godaddy_domain_record`.
- Talks to external GoDaddy REST endpoints over HTTPS.

##### Main Components
a. Terraform CLI / Core
b. Terraform Plugin (the compiled `terraform-provider-godaddy` binary)
– gRPC interface per Terraform Plugin Protocol
– Provider initialization & schema registration
– Resource implementations (CRUD for domain records)
c. Internal GoDaddy API Client (`api` package)
– HTTP-based client wrapping GoDaddy REST calls
d. External GoDaddy DNS REST API
e. User’s HCL configurations & environment variables

##### Relationships & Interactions
1. User writes Terraform HCL → runs `terraform apply`.
2. Terraform Core loads the godaddy plugin binary via plugin protocol.
3. Plugin’s `main.go` spins up gRPC server, initializes provider (reads `key`/`secret`).
4. When Terraform needs to Create/Read/Update/Delete a `godaddy_domain_record`,
the plugin invokes resource handlers in `plugin/godaddy/resource_dns_record.go`.
5. Resource handlers call into the `api/client.go`, forming HTTP requests to GoDaddy’s API.
6. GoDaddy returns JSON HTTP responses → client maps to Go structs → plugin returns state to Terraform.
7. Terraform Core updates state and presents results to the user.

##### Architectural Patterns & Design Principles
- Separation of concerns:
- `plugin/` layer: Terraform SDK glue and resource logic.
- `api/` layer: pure client-SDK for GoDaddy REST API.
- Plugin Protocol Pattern: uses gRPC for IPC between Terraform Core and provider.
- Dependency injection: configuration (`key`, `secret`, optional `customer`) flows into client.
- Testability: local Docker Compose for integration tests, unit tests in each package.

##### Technologies & Frameworks to Call Out
- Go language
- Terraform Plugin SDK (gRPC-based)
- GoDaddy REST API over HTTPS
- Docker & Docker Compose (for local integration)
- GitHub Actions and GoReleaser (CI/CD)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Inputs
    U["User HCL Config\n& Env Vars\n(GODADDY_API_KEY,\nGODADDY_API_SECRET)"]:::user

    %% Terraform Core
    TC["Terraform Core CLI"]:::core

    %% Plugin Binary (gRPC Server)
    PB["terraform-provider-godaddy\n(gRPC Server)"]:::plugin

    %% Plugin Layer
    subgraph "Provider Plugin Layer"
        PG["plugin/godaddy/plugin.go"]:::plugin
        PR["plugin/godaddy/provider.go"]:::plugin
        PC["plugin/godaddy/config.go"]:::plugin
        RD["plugin/godaddy/resource_dns_record.go"]:::plugin
    end

    %% API Client Layer
    subgraph "GoDaddy API Client Layer"
        AC["api/client.go"]:::client
        AD["api/domains.go"]:::client
        AT["api/types.go"]:::client
    end

    %% External GoDaddy API
    GA["GoDaddy DNS REST API\n(HTTPS/JSON)"]:::external

    %% Docker & CI/CD
    subgraph "Infrastructure & CI/CD"
        DK["docker/Dockerfile"]:::infra
        DC["docker/docker-compose.yml"]:::infra
        CI[".github/workflows/release.yml"]:::infra
        GR[".goreleaser.yaml"]:::infra
    end

    %% Tests
    subgraph "Tests"
        IT["api/client_integration_test.go"]:::tests
        TT["api/types_test.go"]:::tests
        PT["plugin/godaddy/provider_test.go"]:::tests
    end

    %% Data Flows
    U -->|"terraform apply"| TC
    TC -->|gRPC Plugin Protocol| PB
    PB --> PG
    PG --> PR
    PR --> PC
    PC --> RD
    RD -->|calls| AC
    RD -->|calls| AD
    RD -->|calls| AT
    AC -->|HTTP Request| GA
    GA -->|JSON Response| AC
    AC --> RD
    RD --> PB
    PB --> TC
    TC -->|"Outputs"| U

    %% Docker & CI/CD connections
    DK -.-> IT
    DC -.-> IT
    CI -.-> GR

    %% Click Events
    click U "https://github.com/n3integration/terraform-provider-godaddy/tree/master/#"
    click PB "https://github.com/n3integration/terraform-provider-godaddy/blob/master/main.go"
    click PG "https://github.com/n3integration/terraform-provider-godaddy/blob/master/plugin/godaddy/plugin.go"
    click PR "https://github.com/n3integration/terraform-provider-godaddy/blob/master/plugin/godaddy/provider.go"
    click PC "https://github.com/n3integration/terraform-provider-godaddy/blob/master/plugin/godaddy/config.go"
    click RD "https://github.com/n3integration/terraform-provider-godaddy/blob/master/plugin/godaddy/resource_dns_record.go"
    click AC "https://github.com/n3integration/terraform-provider-godaddy/blob/master/api/client.go"
    click AD "https://github.com/n3integration/terraform-provider-godaddy/blob/master/api/domains.go"
    click AT "https://github.com/n3integration/terraform-provider-godaddy/blob/master/api/types.go"
    click IT "https://github.com/n3integration/terraform-provider-godaddy/blob/master/api/client_integration_test.go"
    click TT "https://github.com/n3integration/terraform-provider-godaddy/blob/master/api/types_test.go"
    click PT "https://github.com/n3integration/terraform-provider-godaddy/blob/master/plugin/godaddy/provider_test.go"
    click DK "https://github.com/n3integration/terraform-provider-godaddy/tree/master/docker/Dockerfile"
    click DC "https://github.com/n3integration/terraform-provider-godaddy/blob/master/docker/docker-compose.yml"
    click CI "https://github.com/n3integration/terraform-provider-godaddy/blob/master/.github/workflows/release.yml"
    click GR "https://github.com/n3integration/terraform-provider-godaddy/blob/master/.goreleaser.yaml"

    %% Styles
    classDef user fill:#9f6,stroke:#333,stroke-width:1px
    classDef core fill:#bbf,stroke:#333,stroke-width:1px
    classDef plugin fill:#88f,stroke:#333,stroke-width:1px
    classDef client fill:#55f,stroke:#333,stroke-width:1px
    classDef external fill:#f96,stroke:#333,stroke-width:1px
    classDef infra fill:#fdc,stroke:#333,stroke-width:1px
    classDef tests fill:#faa,stroke:#333,stroke-width:1px
```
