# pagerduty/terraform-provider-pagerduty architecture

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

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

## Overview

##### Main Components
- Provider Core: At the heart is main.go, which bootstraps the provider. This is the entry point for the Terraform plugin lifecycle.
- PagerDuty Packages: There are two primary directories—“pagerduty” and “pagerdutyplugin”. Both of these house the bulk of the implementation logic, including resource definitions, data sources, and import functionality for various PagerDuty components (such as users, teams, escalation policies, incident workflows, etc.).
- Caching Mechanism: Notice that the README explains caching support (in-memory and MongoDB) to enhance performance. Represent this as a dedicated component that intercepts/augments the API call flow.
- Utility & Helper Functions: The “util” directory (with subpackages like “apiutil” and “validate”) provide common functionalities used across the project.
- Build & Dev Tools: Directories such as “scripts”, GitHub workflows (in .github/workflows), Makefiles, and other configuration files (like .goreleaser.yml) support continuous integration and deployment, but are not part of the runtime system per se.

##### Relationships and Interactions
- Caching Integration: Show that before and/or after API calls, the caching component (either in-memory or MongoDB) stores response data to improve efficiency. This should be indicated as an interposed layer between the provider logic and PagerDuty’s external API.

##### Architectural Patterns and Design Principles
- Modular Design: The separation between “pagerduty” and “pagerdutyplugin” suggests a modular use of components, perhaps to manage different types of PagerDuty resources or even to support different API versions.
- Caching Strategy: Highlight the two caching methods as design choices that improve performance when calling PagerDuty’s APIs.

##### Relevant Technologies
- Go as the primary language.
- Terraform Plugin Framework (or SDK version, as appropriate) as the interface between Terraform and the provider.
- The caching solutions: in-memory and MongoDB (with configuration options reflected by the TF_PAGERDUTY_CACHE environment variable).
- GitHub workflows (CI/CD) and Makefile-based builds.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Terraform Ecosystem
    TCore["Terraform Core"]:::terraform

    %% Provider Binary Entry
    Provider["Provider Core (main.go)"]:::provider

    %% PagerDuty Packages
    PD_Business["PagerDuty Business Logic"]:::resource
    PD_Plugin["PagerDuty Plugin Logic"]:::resource

    %% Caching Layer
    Caching["Caching Layer"]:::caching

    %% External API
    PagerDutyAPI["PagerDuty API"]:::external

    %% Utility Modules
    Utility["Utility Modules"]:::utility

    %% CI/CD & Dev Tools
    CI_CD["CI/CD & Dev Tools"]:::build

    %% Relationships
    TCore -->|"invokes"| Provider
    Provider -->|"calls_business"| PD_Business
    Provider -->|"calls_plugin"| PD_Plugin
    PD_Business -->|"utilizes_caching"| Caching
    PD_Plugin -->|"utilizes_caching"| Caching
    Caching -->|"forwards_to"| PagerDutyAPI
    Utility ---|"supports"| PD_Business
    Utility ---|"supports"| PD_Plugin
    CI_CD -.->|"triggers"| Provider

    %% Click Events
    click Provider "https://github.com/pagerduty/terraform-provider-pagerduty/blob/master/main.go"
    click PD_Business "https://github.com/pagerduty/terraform-provider-pagerduty/blob/master/pagerduty/provider.go"
    click PD_Plugin "https://github.com/pagerduty/terraform-provider-pagerduty/blob/master/pagerdutyplugin/provider.go"
    click Caching "https://github.com/pagerduty/terraform-provider-pagerduty/blob/master/pagerduty/event_orchestration_cache_variable_util.go"
    click Utility "https://github.com/pagerduty/terraform-provider-pagerduty/tree/master/util"
    click CI_CD "https://github.com/pagerduty/terraform-provider-pagerduty/tree/master/.github/workflows"

    %% Styles
    classDef terraform fill:#a2d2ff,stroke:#034078,stroke-width:2px
    classDef provider fill:#a9def9,stroke:#034078,stroke-width:2px
    classDef resource fill:#ffafcc,stroke:#d62828,stroke-width:2px
    classDef caching fill:#cdb4db,stroke:#7209b7,stroke-width:2px
    classDef external fill:#ffffb3,stroke:#f4a261,stroke-width:2px
    classDef utility fill:#fdffb6,stroke:#2b2d42,stroke-width:2px
    classDef build fill:#ffddd2,stroke:#ff6b6b,stroke-width:2px
```
