# watonomous/terraform-provider-email architecture

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

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

## Overview

##### Project Type and Purpose
- This is a Terraform “provider” plugin written in Go.
- Its sole purpose is to implement a Terraform resource that sends emails via SMTP when Terraform applies a configuration.

##### File Structure
- Top-level files:
- main.go – entry point registering the provider plugin
- go.mod / go.sum – Go module definitions
- Makefile / .goreleaser.yml – build, test, release automation
- terraform-registry-manifest.json – Terraform Registry metadata
- email/:
- provider.go – constructs the Provider schema, configuration (SMTP host, port, credentials)
- resource_email.go – implements the “email” resource’s Create/Read/Update/Delete logic via SMTP
- provider_test.go – unit tests for provider functions
- docs/, examples/ – user documentation and sample Terraform configs
- tools/ – helper utilities used in CI or code generation

##### README for Insights
- Uses HashiCorp Terraform Plugin SDK
- Tests with a local SMTP server (rnwood/smtp4dev) in acceptance tests
- Generates docs via `go generate`

##### Main Components & Interactions
a. Terraform Core
– CLI + engine that parses .tf files, initializes providers, and drives plan/apply.
b. Provider Plugin (this project’s binary)
– Exposes gRPC endpoints via HashiCorp go-plugin.
– Defines the Provider and the “email” resource.
– Uses Go’s net/smtp or a similar SMTP client to connect to an SMTP server.
c. External SMTP Server
– Real SMTP or test SMTP (smtp4dev) that accepts email messages.
d. User Terraform Configuration
– example/main.tf invoking the “email” resource with parameters (to, from, subject, body).

##### Architectural Patterns & Principles
- Plugin Architecture (hashicorp/go-plugin) – decouples Terraform Core from provider implementation.
- Resource CRUD model – each Terraform resource implements Create, Read, Update, Delete operations in code.
- Configuration-driven design – all SMTP settings are passed via Terraform resource or provider block.
- Separation of concerns:
- Provider schema & configuration (provider.go)
- Resource implementation (resource_email.go)
- Documentation & examples (docs/, examples/)
- Automation & CI (Makefile, .github/workflows, .goreleaser.yml)

##### Detailed Element Checklist
- Component labels: “Terraform CLI”, “Terraform Engine”, “Email Provider Plugin”
- Optional note on code-generation step (`go generate ./...` → docs)

- User’s Terraform files driving Terraform Core
- The provider plugin’s internal decomposition (schema, resource logic, SMTP client)
- External SMTP service interaction
- CI/CD automation surrounding build, test, and release

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        UL_Config["Terraform Configuration (.tf)"]:::user
    end

    %% Terraform Core
    subgraph "Terraform Core"
        TC_CLI["Terraform CLI"]:::runtime
        TC_Engine["Terraform Engine"]:::runtime
    end

    %% Provider Plugin Process
    subgraph "Email Provider Plugin" 
        direction TB
        PP_Schema["Provider Schema & Configuration"]:::runtime
        PP_Resource["Email Resource CRUD Implementation"]:::runtime
        PP_SMTPClient["SMTP Client (net/smtp)"]:::runtime
    end

    %% External Services
    subgraph "External SMTP Service"
        SMTP["SMTP Server (SMTP:25)"]:::external
        SMTP_Test["smtp4dev (Test)"]:::external_dashed
    end

    %% CI/CD Tools
    subgraph "CI/CD & Automation"
        CI_Make["Makefile"]:::ci
        CI_Goreleaser[".goreleaser.yml"]:::ci
        CI_Workflow["GitHub Actions Release"]:::ci
        CI_Tools["tools/tools.go"]:::ci
    end

    %% Additional Project Files
    subgraph "Project Files"
        Main["main.go"]:::runtime
        GoMod["go.mod"]:::runtime
        GoSum["go.sum"]:::runtime
        TFRegistry["terraform-registry-manifest.json"]:::runtime
        README["README.md"]:::user
        DocsIndex["docs/index.md"]:::user
        DocsEmail["docs/resources/email.md"]:::user
        ExampleTF["examples/main.tf"]:::user
        ProviderTest["email/provider_test.go"]:::runtime
    end

    %% Connections
    UL_Config -->|"terraform apply"| TC_CLI
    TC_CLI --> TC_Engine
    TC_Engine -->|"gRPC/stdio"| Main
    Main --> PP_Schema
    PP_Schema --> PP_Resource
    PP_Resource --> PP_SMTPClient
    PP_SMTPClient -->|"SMTP:25"| SMTP
    PP_SMTPClient -->|"SMTP:25"| SMTP_Test

    %% CI/CD flows
    CI_Make --> Main
    CI_Make --> PP_Resource
    CI_Make --> ProviderTest
    CI_Goreleaser --> Main
    CI_Workflow --> CI_Goreleaser
    CI_Tools --> ProviderTest

    %% Click Events
    click Main "https://github.com/watonomous/terraform-provider-email/blob/main/main.go"
    click GoMod "https://github.com/watonomous/terraform-provider-email/blob/main/go.mod"
    click GoSum "https://github.com/watonomous/terraform-provider-email/blob/main/go.sum"
    click CI_Make "https://github.com/watonomous/terraform-provider-email/tree/main/Makefile"
    click CI_Goreleaser "https://github.com/watonomous/terraform-provider-email/blob/main/.goreleaser.yml"
    click CI_Workflow "https://github.com/watonomous/terraform-provider-email/blob/main/.github/workflows/release.yml"
    click TFRegistry "https://github.com/watonomous/terraform-provider-email/blob/main/terraform-registry-manifest.json"
    click PP_Schema "https://github.com/watonomous/terraform-provider-email/blob/main/email/provider.go"
    click PP_Resource "https://github.com/watonomous/terraform-provider-email/blob/main/email/resource_email.go"
    click ProviderTest "https://github.com/watonomous/terraform-provider-email/blob/main/email/provider_test.go"
    click DocsIndex "https://github.com/watonomous/terraform-provider-email/blob/main/docs/index.md"
    click DocsEmail "https://github.com/watonomous/terraform-provider-email/blob/main/docs/resources/email.md"
    click ExampleTF "https://github.com/watonomous/terraform-provider-email/blob/main/examples/main.tf"
    click CI_Tools "https://github.com/watonomous/terraform-provider-email/blob/main/tools/tools.go"
    click README "https://github.com/watonomous/terraform-provider-email/blob/main/README.md"

    %% Styles
    classDef user fill:#e0f7e0,stroke:#2f6627,color:#2f6627;
    classDef runtime fill:#e0f0ff,stroke:#2f4a7d,color:#2f4a7d;
    classDef external fill:#ffe0b2,stroke:#b35f00,color:#b35f00;
    classDef external_dashed fill:#ffe0b2,stroke:#b35f00,color:#b35f00,stroke-dasharray: 5 5;
    classDef ci fill:#eeeeee,stroke:#666666,color:#333333;
```
