# scaleway/terraform-provider-scaleway architecture

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

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

## Overview

##### Main Components
- Terraform Core and Plugin Interface – Represent Terraform’s mechanism of loading provider plugins. Note that this provider is compiled as a Go binary and invoked by Terraform.
- Provider Binary (Entry Point) – Use “cmd/tftemplate” as the starting point where the provider is built and launched.
- Service Modules – Outline the various service components grouped under “internal/services”. You might want to represent each service group (for example, account, iam, vpc, lb, instance, etc.) as separate modules; these represent the different resource types and data sources the provider supports.
- Core Library & Utilities – Include modules that handle common functionality like request retry/logging (“internal/transport”, “internal/logging”), error handling (“internal/httperrors”), and metadata extraction (“internal/meta”). These core utilities support virtually all service modules.
- CI/CD and Developer Tools – Though not directly part of the runtime architecture, the .github workflows, Docker configurations, and scripts represent the automation pipeline for building, testing, and releasing the provider.
- External Scaleway API – Represent an external cloud system that the provider interacts with. This includes the Scaleway API endpoints that are being enclosed through the provider’s service modules.

##### Relationships and Interactions
- Optionally, illustrate the developer workflow (CI/CD pipelines, containerized development environments under .devcontainer, scripts for linting and formatting) that feed into the building and testing of the provider.

##### Important Architectural Patterns and Design Principles
- Modularity – The clear separation of services (each in its own folder under “internal/services”) supports independent development and testing.
- Abstraction & Reusability – Common behaviors (such as retries, logging, and error handling) are abstracted out into shared libraries.
- Testability – With directories dedicated to acceptance tests (“internal/acctest”) and unit tests integrated in each service, the design emphasizes rigorous testing.
- Plugin-based Architecture – The provider is meant to be compiled separately and plugged into Terraform, following the plugin interaction design required by Terraform.

##### Relevant Technologies and Frameworks
- Go (Golang) – The entire project is implemented in Go.
- Terraform Provider Framework – Although not explicitly detailed in the file tree, the provider conforms to Terraform’s plugin interface standards.
- CI/CD/Devcontainer – Docker and GitHub Actions (.github/workflows) provide containerized and automated build/test environments.
- Testing Tools – Testing and acceptance tests (including VCR-like cassette testing) ensure API calls are correctly recorded and replayed.

##### Final Advice
- Be as detailed as possible, ensuring that each pathway (from Terraform invocation, through the provider’s internal structure, down to external API calls) is captured.
- Utilize layers: one for the plugin interface, one for business logic (service modules and utilities), and one for external systems.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Terraform & Provider Layer
    subgraph "Terraform & Provider"
        A["Terraform Core"]:::terraform
        B["Provider Binary (cmd/tftemplate)"]:::provider
    end

    %% Service Modules Layer
    subgraph "Service Modules"
        S1["Account Module"]:::service
        S2["Other Service Modules"]:::service
    end

    %% Core Utilities Layer
    subgraph "Core Utilities"
        U1["Transport"]:::utility
        U2["HTTP Errors"]:::utility
        U3["Logging"]:::utility
        U4["Metadata Extraction"]:::utility
    end

    %% External API
    E["External Scaleway API"]:::external

    %% Testing & DevOps Layer
    subgraph "Testing & DevOps"
        T["Acceptance & Testing (acctest)"]:::testing
        C1["CI/CD Workflows"]:::cicd
        C2["Developer Containers"]:::cicd
        C3["Utility Scripts"]:::cicd
    end

    %% Relationships
    A -->|"sends-config"| B
    B -->|"calls"| S1
    B -->|"calls"| S2
    S1 -->|"uses"| U1
    S1 -->|"uses"| U2
    S1 -->|"uses"| U3
    S1 -->|"uses"| U4
    S2 -->|"uses"| U1
    S2 -->|"uses"| U2
    S2 -->|"uses"| U3
    S2 -->|"uses"| U4
    U1 -->|"communicates"| E
    U2 -->|"communicates"| E
    U3 -->|"communicates"| E
    U4 -->|"communicates"| E
    T -->|"validates"| B
    C1 -->|"automates"| B
    C2 -->|"automates"| B
    C3 -->|"automates"| B

    %% Click Events
    click A "https://github.com/scaleway/terraform-provider-scaleway/blob/master/cmd/tftemplate/main.go"
    click B "https://github.com/scaleway/terraform-provider-scaleway/blob/master/cmd/tftemplate/main.go"
    click S1 "https://github.com/scaleway/terraform-provider-scaleway/tree/master/internal/services/account"
    click U1 "https://github.com/scaleway/terraform-provider-scaleway/tree/master/internal/transport"
    click U2 "https://github.com/scaleway/terraform-provider-scaleway/tree/master/internal/httperrors"
    click U3 "https://github.com/scaleway/terraform-provider-scaleway/tree/master/internal/logging"
    click U4 "https://github.com/scaleway/terraform-provider-scaleway/tree/master/internal/meta"
    click T "https://github.com/scaleway/terraform-provider-scaleway/tree/master/internal/acctest"
    click C1 "https://github.com/scaleway/terraform-provider-scaleway/tree/master/.github/workflows"
    click C2 "https://github.com/scaleway/terraform-provider-scaleway/blob/master/.devcontainer"
    click C3 "https://github.com/scaleway/terraform-provider-scaleway/tree/master/scripts"

    %% Styles
    classDef terraform fill:#ccf,stroke:#333,stroke-width:2px;
    classDef provider fill:#cfc,stroke:#333,stroke-width:2px;
    classDef service fill:#ffc,stroke:#333,stroke-width:2px;
    classDef utility fill:#d9b3ff,stroke:#333,stroke-width:2px;
    classDef external fill:#ffb3b3,stroke:#333,stroke-width:2px;
    classDef testing fill:#efe,stroke:#333,stroke-width:2px;
    classDef cicd fill:#cfe,stroke:#333,stroke-width:2px;
```
