# marshallford/terraform-provider-pfsense architecture

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

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

## Overview

#### Purpose and Entry Point

This is a Go Terraform provider that configures pfSense CE firewalls/routers (validated for pfSense 2.6.0–2.8.1). Terraform loads the provider binary through `main.go`, which serves the provider implementation in `internal/provider/provider.go`. The provider exposes managed resources, read-only data sources, and imperative-style actions for DHCPv4, DNS Resolver, firewall aliases/filter reload, PHP execution, and system version queries.

#### Terraform Provider Boundary

`internal/provider/provider.go` defines provider schema, configuration, and registration of resource/data-source/action implementations. Provider-specific Terraform type handling, plan semantics, and validation are centralized in:
- `internal/provider/provider_custom_types.go`
- `internal/provider/provider_plan_modifiers.go`
- `internal/provider/validators.go`

Terraform configuration is translated into provider models and then delegated to the pfSense client layer; Terraform state is reconstructed from pfSense responses during reads.

#### Resource and Data-Source Domains

The main declarative domains are:
- DHCP static mappings and DHCP apply: `internal/provider/dhcpv4_staticmapping_resource.go`, `internal/provider/dhcpv4_staticmappings_data_source.go`, `internal/provider/dhcpv4_apply_resource.go`
- DNS Resolver config file, host/domain overrides, and apply: `internal/provider/dnsresolver_configfile_resource.go`, `internal/provider/dnsresolver_hostoverride_resource.go`, `internal/provider/dnsresolver_domainoverride_resource.go`
- Firewall IP/port aliases and filter reload: `internal/provider/firewall_ip_alias_resource.go`, `internal/provider/firewall_port_alias_resource.go`, `internal/provider/firewall_filter_reload_resource.go`

Common files within each domain hold shared schema/model and CRUD translation logic, separating Terraform-facing lifecycle code from shared operations.

#### Actions and Command Execution

Actions provide explicit operations that are not necessarily persistent objects, including applying DHCP/DNS changes, reloading firewall filters, and executing pfSense PHP:
- `internal/provider/dhcpv4_apply_action.go`
- `internal/provider/dnsresolver_apply_action.go`
- `internal/provider/execute_php_command_action.go`

PHP execution is also available as a resource and data source (`internal/provider/execute_php_command_resource.go`, `internal/provider/execute_php_command_data_source.go`), making it an escape hatch for operations not covered by typed provider features.

#### pfSense Integration Layer

`pkg/pfsense` is the infrastructure boundary between Terraform semantics and pfSense. `pkg/pfsense/client.go` owns client construction/session behavior; `pkg/pfsense/http.go` and `pkg/pfsense/html.go` handle HTTP and pfSense web-interface response processing. Domain APIs encapsulate pfSense operations:
- `pkg/pfsense/dhcpv4_staticmapping.go`
- `pkg/pfsense/dnsresolver_hostoverride.go`
- `pkg/pfsense/firewall_ip_alias.go`

This layer also owns privilege handling (`pkg/pfsense/privileges.go`), validation, and pfSense-specific error mapping, preventing web/UI protocol concerns from leaking into Terraform resource implementations.

#### Primary Flow and Operational Boundaries

Terraform plan/apply invokes provider resource or action handlers; handlers validate and map Terraform values, call `pkg/pfsense`, then persist IDs and observed values into Terraform state. Reads/data sources retrieve and normalize current pfSense configuration. Mutating configuration and activating it are intentionally separable: DNS/DHCP “apply” and firewall filter reload endpoints trigger runtime adoption after related configuration changes.

The external runtime boundary is the pfSense administration interface, reached over HTTP(S) and using pfSense’s web/PHP mechanisms rather than a separate documented API.

#### Build, Distribution, and Documentation

The provider is built with Go modules (`go.mod`) and released as a Terraform provider using `terraform-registry-manifest.json` and `.goreleaser.yml`. CI/release automation resides in `.github/workflows/ci.yml` and `.github/workflows/release.yml`. Generated registry documentation is organized under `docs/`, with template support in `templates/index.md.tmpl`.

Main entry points: [`internal/provider/provider.go`](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/provider.go) (Provider registration), [`pkg/pfsense/client.go`](https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/client.go) (pfSense client), [`main.go`](https://github.com/marshallford/terraform-provider-pfsense/blob/main/main.go) (Provider binary), [`.goreleaser.yml`](https://github.com/marshallford/terraform-provider-pfsense/blob/main/.goreleaser.yml) (Provider release packaging)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_terraform["Terraform provider"]
  node_main["Provider binary<br/>Go entry point<br/>[main.go]"]
  node_provider["Provider registration<br/>Terraform provider<br/>[provider.go]"]
  node_terraform_semantics["Types, planning &amp; validation<br/>provider semantics"]
end

subgraph group_domains["Provider domains"]
  node_dhcp["DHCPv4 mappings<br/>resource domain"]
  node_dns["DNS Resolver<br/>resource domain"]
  node_firewall["Firewall aliases<br/>resource domain"]
  node_activation["Apply &amp; filter reload<br/>Terraform actions"]
  node_php["PHP command escape hatch"]
end

subgraph group_pfsense["pfSense integration"]
  node_client["pfSense client<br/>integration client<br/>[client.go]"]
  node_domain_apis["pfSense domain APIs<br/>integration operations"]
  node_web_protocol["HTTP &amp; HTML processing<br/>web protocol adapter<br/>[http.go]"]
  node_privileges["Privileges &amp; error mapping<br/>pfSense boundary<br/>[privileges.go]"]
end

subgraph group_delivery["Build &amp; release"]
  node_build["Go module build<br/>build definition<br/>[go.mod]"]
  node_release["Provider release packaging<br/>release automation<br/>[.goreleaser.yml]"]
  node_registry["Terraform Registry metadata<br/>distribution metadata"]
  node_docs["Generated documentation<br/>provider documentation<br/>[index.md]"]
end

node_terraform_cli{{"Terraform CLI<br/>runtime"}}
node_pfsense_ui{{"pfSense administration interface<br/>external system"}}

node_terraform_cli -->|"loads"| node_main
node_main -->|"serves"| node_provider
node_provider -->|"uses"| node_terraform_semantics
node_provider -->|"registers"| node_dhcp
node_provider -->|"registers"| node_dns
node_provider -->|"registers"| node_firewall
node_provider -->|"registers"| node_activation
node_provider -->|"registers"| node_php
node_dhcp -->|"maps state and calls"| node_client
node_dns -->|"maps state and calls"| node_client
node_firewall -->|"maps state and calls"| node_client
node_activation -->|"triggers via"| node_client
node_php -->|"executes via"| node_client
node_client -->|"provides"| node_domain_apis
node_client -->|"uses"| node_web_protocol
node_client -->|"enforces"| node_privileges
node_web_protocol -->|"HTTP&#40;S&#41;"| node_pfsense_ui
node_build -->|"builds"| node_main
node_release -->|"packages"| node_build
node_release -->|"publishes with"| node_registry
node_provider -.->|"documented as"| node_docs

click node_main "https://github.com/marshallford/terraform-provider-pfsense/blob/main/main.go"
click node_provider "https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/provider.go"
click node_terraform_semantics "https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/provider_custom_types.go"
click node_dhcp "https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/dhcpv4_staticmapping_resource.go"
click node_dns "https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/dnsresolver_configfile_resource.go"
click node_firewall "https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/firewall_ip_alias_resource.go"
click node_activation "https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/dhcpv4_apply_action.go"
click node_php "https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/execute_php_command_action.go"
click node_client "https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/client.go"
click node_domain_apis "https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/dhcpv4_staticmapping.go"
click node_web_protocol "https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/http.go"
click node_privileges "https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/privileges.go"
click node_build "https://github.com/marshallford/terraform-provider-pfsense/blob/main/go.mod"
click node_release "https://github.com/marshallford/terraform-provider-pfsense/blob/main/.goreleaser.yml"
click node_registry "https://github.com/marshallford/terraform-provider-pfsense/blob/main/terraform-registry-manifest.json"
click node_docs "https://github.com/marshallford/terraform-provider-pfsense/blob/main/docs/index.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_provider,node_terraform_semantics toneBlue
class node_dhcp,node_dns,node_firewall,node_activation,node_php toneAmber
class node_client,node_domain_apis,node_web_protocol,node_privileges toneMint
class node_build,node_release,node_registry,node_docs toneRose
class node_terraform_cli,node_pfsense_ui toneNeutral
```

## Components

### Terraform provider

- [Provider binary](https://github.com/marshallford/terraform-provider-pfsense/blob/main/main.go): Go entry point · `main.go`
- [Provider registration](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/provider.go): Terraform provider · Registers schemas, resources, data sources, and actions. · `internal/provider/provider.go`
- [Types, planning & validation](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/provider_custom_types.go): provider semantics · `internal/provider/provider_custom_types.go`

### Provider domains

- [DHCPv4 mappings](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/dhcpv4_staticmapping_resource.go): resource domain · Static mapping CRUD, lookup, and runtime apply support. · `internal/provider/dhcpv4_staticmapping_resource.go`
- [DNS Resolver](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/dnsresolver_configfile_resource.go): resource domain · Manages resolver config, host overrides, and domain overrides. · `internal/provider/dnsresolver_configfile_resource.go`
- [Firewall aliases](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/firewall_ip_alias_resource.go): resource domain · Manages IP and port aliases. · `internal/provider/firewall_ip_alias_resource.go`
- [Apply & filter reload](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/dhcpv4_apply_action.go): Terraform actions · Separately activates DHCP/DNS changes and reloads firewall filters. · `internal/provider/dhcpv4_apply_action.go`
- [PHP command escape hatch](https://github.com/marshallford/terraform-provider-pfsense/blob/main/internal/provider/execute_php_command_action.go): resource, data source & action · Executes pfSense PHP for operations outside typed domains. · `internal/provider/execute_php_command_action.go`

### pfSense integration

- [pfSense client](https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/client.go): integration client · Owns session construction and pfSense operation access. · `pkg/pfsense/client.go`
- [pfSense domain APIs](https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/dhcpv4_staticmapping.go): integration operations · Encapsulates DHCP, DNS, and firewall web-interface operations. · `pkg/pfsense/dhcpv4_staticmapping.go`
- [HTTP & HTML processing](https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/http.go): web protocol adapter · Processes pfSense administration-interface requests and responses. · `pkg/pfsense/http.go`
- [Privileges & error mapping](https://github.com/marshallford/terraform-provider-pfsense/blob/main/pkg/pfsense/privileges.go): pfSense boundary · `pkg/pfsense/privileges.go`

### Build & release

- [Go module build](https://github.com/marshallford/terraform-provider-pfsense/blob/main/go.mod): build definition · `go.mod`
- [Provider release packaging](https://github.com/marshallford/terraform-provider-pfsense/blob/main/.goreleaser.yml): release automation · Builds distributable Terraform provider releases. · `.goreleaser.yml`
- [Terraform Registry metadata](https://github.com/marshallford/terraform-provider-pfsense/blob/main/terraform-registry-manifest.json): distribution metadata · `terraform-registry-manifest.json`
- [Generated documentation](https://github.com/marshallford/terraform-provider-pfsense/blob/main/docs/index.md): provider documentation · `docs/index.md`

### Other components

- **Terraform CLI**: runtime · Loads the provider and invokes plan, read, and apply operations.
- **pfSense administration interface**: external system · HTTP(S) web and PHP mechanisms, not a separate documented API.

## Connections

- Terraform CLI → Provider binary: loads
- Provider binary → Provider registration: serves
- Provider registration → Types, planning & validation: uses
- Provider registration → DHCPv4 mappings: registers
- Provider registration → DNS Resolver: registers
- Provider registration → Firewall aliases: registers
- Provider registration → Apply & filter reload: registers
- Provider registration → PHP command escape hatch: registers
- DHCPv4 mappings → pfSense client: maps state and calls
- DNS Resolver → pfSense client: maps state and calls
- Firewall aliases → pfSense client: maps state and calls
- Apply & filter reload → pfSense client: triggers via
- PHP command escape hatch → pfSense client: executes via
- pfSense client → pfSense domain APIs: provides
- pfSense client → HTTP & HTML processing: uses
- pfSense client → Privileges & error mapping: enforces
- HTTP & HTML processing → pfSense administration interface: HTTP(S)
- Go module build → Provider binary: builds
- Provider release packaging → Go module build: packages
- Provider release packaging → Terraform Registry metadata: publishes with
- Provider registration → Generated documentation: documented as
