# hashicorp/terraform-provider-dns architecture

> Architecture diagram of the GitHub repository hashicorp/terraform-provider-dns, 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/hashicorp/terraform-provider-dns
- Repository: https://github.com/hashicorp/terraform-provider-dns

## Overview

#### Purpose and Entrypoint
This Go repository implements HashiCorp’s Terraform DNS provider. It exposes Terraform resources that create/update DNS records through RFC 2136 dynamic updates and data sources that query DNS records. The plugin executable begins at `main.go`; provider construction and Terraform registration are centered in `internal/provider/provider.go` and `internal/provider/provider_framework.go`.

#### Terraform Plugin Boundary
Terraform CLI launches the provider as a separate plugin process using Terraform Plugin Protocol v5. The provider translates Terraform configuration, planning, state, and CRUD/read requests into its internal DNS operations. Provider schema, resource/data-source registration, and framework integration are defined in:
- `internal/provider/provider.go`
- `internal/provider/provider_framework.go`
- `internal/provider/config.go`

#### Provider Configuration and Authentication
A shared provider configuration establishes DNS server connectivity and authentication used by all resources and data sources. It supports TSIG secret-key transaction authentication and Kerberos/GSS-TSIG. Configuration is transformed into DNS client behavior before request handling:
- `internal/provider/config.go`
- `internal/provider/provider.go`
- `examples/provider/provider_gss_tsig.tf`

This is the main security boundary: Terraform-supplied credentials and server settings become authenticated DNS transport configuration.

#### Record Resource Lifecycle
Mutable Terraform resources model individual records or record sets. Their create/update/delete lifecycle performs RFC 2136 DNS UPDATE operations, while read refreshes Terraform state from DNS. Record-specific implementations separate DNS semantics by type:
- `internal/provider/resource_dns_a_record_set.go`
- `internal/provider/resource_dns_cname_record.go`
- `internal/provider/resource_dns_srv_record_set.go`

The resource surface includes A/AAAA, CNAME, MX, NS, PTR, SRV, and TXT forms. State identity and collection stability rely on hashing where appropriate, including `internal/hashcode/hashcode.go` and `internal/provider/hash_ip_string.go`.

#### DNS Read Data Sources
Read-only data sources resolve existing DNS records and return results into Terraform expressions without modifying DNS. Type-specific schemas adapt lookup output to Terraform state:
- `internal/provider/data_dns_a_record_set.go`
- `internal/provider/data_dns_cname_record_set.go`
- `internal/provider/data_dns_txt_record_set.go`

The shared lookup layer is `internal/provider/lookup.go`, forming the boundary between record/data-source logic and DNS query execution.

#### Validation and DNS Naming Rules
Validation rejects malformed zones, record names, and provider inputs before external DNS calls. This protects the resource and data-source layers from invalid Terraform configuration:
- `internal/provider/validators.go`
- `internal/validators/dnsvalidator/is_record_name_valid.go`
- `internal/validators/dnsvalidator/is_zone_name_valid.go`

#### External Runtime, Test Infrastructure, and Delivery
Production runtime dependencies are Terraform CLI/plugin protocol, reachable authoritative DNS servers, and optionally TSIG or Kerberos infrastructure. Acceptance tests provision a Docker-based DNS/Kerberos environment and invoke real Terraform/provider processes:
- `internal/provider/acceptance.sh`
- `internal/provider/testdata/Dockerfile`
- `internal/provider/testdata/named.conf.kerberos`

GitHub Actions builds, tests, and publishes release artifacts; Terraform Registry documentation is generated into `docs/` from templates and provider schemas:
- `.github/workflows/build.yml`
- `GNUmakefile`
- `templates/index.md.tmpl`

Main entry points: [`internal/provider/provider.go`](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/provider.go) (Provider Registration), [`internal/provider/resource_dns_a_record_set.go`](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/resource_dns_a_record_set.go) (Record Resources), [`internal/provider/config.go`](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/config.go) (Shared DNS Config), [`internal/provider/acceptance.sh`](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/acceptance.sh) (Acceptance Environment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_plugin["Terraform Plugin"]
  node_main["Plugin Entrypoint<br/>Go executable<br/>[main.go]"]
  node_provider["Provider Registration<br/>provider SDK<br/>[provider.go]"]
  node_framework["Framework Integration<br/>provider framework"]
end

subgraph group_dns["DNS Operations"]
  node_config["Shared DNS Config<br/>configuration<br/>[config.go]"]
  node_resources["Record Resources<br/>Terraform resources"]
  node_recordtypes["Record Type Semantics<br/>resource implementation"]
  node_hashing["State Hashing<br/>state identity<br/>[hashcode.go]"]
  node_datasources["DNS Data Sources<br/>Terraform data sources"]
  node_lookup["DNS Lookup Layer<br/>query boundary<br/>[lookup.go]"]
  node_auth{{"TSIG / GSS-TSIG<br/>authentication"}}
end

subgraph group_delivery["Validation &amp; Delivery"]
  node_validation["Provider Validation<br/>[validators.go]"]
  node_dnsvalidator["DNS Name Rules<br/>validation rules"]
  node_acceptance["Acceptance Environment<br/>test infrastructure<br/>[acceptance.sh]"]
  node_ci["GitHub Actions<br/>CI/CD<br/>[build.yml]"]
  node_docs["Registry Documentation<br/>documentation generation<br/>[index.md.tmpl]"]
end

node_terraform{{"Terraform CLI<br/>external runtime"}}
node_dnsserver[("Authoritative DNS Server<br/>external service")]

node_terraform -->|"launches"| node_main
node_main -->|"starts"| node_provider
node_provider -->|"integrates"| node_framework
node_provider -->|"configures"| node_config
node_provider -->|"validates inputs"| node_validation
node_validation -->|"applies naming rules"| node_dnsvalidator
node_provider -->|"registers"| node_resources
node_resources -->|"dispatches to"| node_recordtypes
node_resources -->|"uses"| node_hashing
node_provider -->|"registers"| node_datasources
node_datasources -->|"queries through"| node_lookup
node_config -->|"supports"| node_auth
node_config -->|"configures client for"| node_dnsserver
node_resources -->|"RFC 2136 UPDATE"| node_dnsserver
node_lookup -->|"DNS queries"| node_dnsserver
node_auth -->|"authenticates updates"| node_dnsserver
node_acceptance -.->|"runs real processes"| node_terraform
node_acceptance -.->|"provisions DNS/Kerberos"| node_dnsserver
node_ci -->|"executes tests"| node_acceptance
node_ci -->|"generates"| node_docs
node_provider -.->|"supplies schemas"| node_docs

click node_main "https://github.com/hashicorp/terraform-provider-dns/blob/main/main.go"
click node_provider "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/provider.go"
click node_framework "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/provider_framework.go"
click node_config "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/config.go"
click node_validation "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/validators.go"
click node_dnsvalidator "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/validators/dnsvalidator/is_record_name_valid.go"
click node_resources "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/resource_dns_a_record_set.go"
click node_recordtypes "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/resource_dns_srv_record_set.go"
click node_hashing "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/hashcode/hashcode.go"
click node_datasources "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/data_dns_a_record_set.go"
click node_lookup "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/lookup.go"
click node_auth "https://github.com/hashicorp/terraform-provider-dns/blob/main/examples/provider/provider_gss_tsig.tf"
click node_acceptance "https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/acceptance.sh"
click node_ci "https://github.com/hashicorp/terraform-provider-dns/blob/main/.github/workflows/build.yml"
click node_docs "https://github.com/hashicorp/terraform-provider-dns/blob/main/templates/index.md.tmpl"

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_framework toneBlue
class node_config,node_resources,node_recordtypes,node_hashing,node_datasources,node_lookup,node_auth toneAmber
class node_validation,node_dnsvalidator,node_acceptance,node_ci,node_docs toneMint
class node_terraform,node_dnsserver toneNeutral
```

## Components

### Terraform Plugin

Provider process and Terraform-facing registration.

- [Plugin Entrypoint](https://github.com/hashicorp/terraform-provider-dns/blob/main/main.go): Go executable · `main.go`
- [Provider Registration](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/provider.go): provider SDK · Registers schemas, resources, and data sources. · `internal/provider/provider.go`
- [Framework Integration](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/provider_framework.go): provider framework · `internal/provider/provider_framework.go`

### DNS Operations

Authenticated update and lookup paths.

- [Shared DNS Config](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/config.go): configuration · Converts provider settings and credentials into DNS client behavior. · `internal/provider/config.go`
- [Record Resources](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/resource_dns_a_record_set.go): Terraform resources · Implements mutable A/AAAA, CNAME, MX, NS, PTR, SRV, and TXT records. · `internal/provider/resource_dns_a_record_set.go`
- [Record Type Semantics](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/resource_dns_srv_record_set.go): resource implementation · Type-specific lifecycle behavior, including CNAME and SRV record sets. · `internal/provider/resource_dns_srv_record_set.go`
- [State Hashing](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/hashcode/hashcode.go): state identity · Stabilizes collection and record identity. · `internal/hashcode/hashcode.go`
- [DNS Data Sources](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/data_dns_a_record_set.go): Terraform data sources · Maps DNS lookup results into Terraform state. · `internal/provider/data_dns_a_record_set.go`
- [DNS Lookup Layer](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/lookup.go): query boundary · Executes shared DNS read queries. · `internal/provider/lookup.go`
- [TSIG / GSS-TSIG](https://github.com/hashicorp/terraform-provider-dns/blob/main/examples/provider/provider_gss_tsig.tf): authentication · Optional transaction authentication, including Kerberos. · `examples/provider/provider_gss_tsig.tf`

### Validation & Delivery

Input safeguards, acceptance environment, and release workflow.

- [Provider Validation](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/validators.go): validation · Rejects invalid provider and record inputs before DNS calls. · `internal/provider/validators.go`
- [DNS Name Rules](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/validators/dnsvalidator/is_record_name_valid.go): validation rules · Validates record and zone names. · `internal/validators/dnsvalidator/is_record_name_valid.go`
- [Acceptance Environment](https://github.com/hashicorp/terraform-provider-dns/blob/main/internal/provider/acceptance.sh): test infrastructure · Docker DNS/Kerberos environment for real provider and Terraform runs. · `internal/provider/acceptance.sh`
- [GitHub Actions](https://github.com/hashicorp/terraform-provider-dns/blob/main/.github/workflows/build.yml): CI/CD · Builds, tests, and publishes release artifacts. · `.github/workflows/build.yml`
- [Registry Documentation](https://github.com/hashicorp/terraform-provider-dns/blob/main/templates/index.md.tmpl): documentation generation · Generates docs from templates and provider schemas. · `templates/index.md.tmpl`

### Other components

- **Terraform CLI**: external runtime · Launches the provider through Plugin Protocol v5.
- **Authoritative DNS Server**: external service · Receives RFC 2136 updates and serves record queries.

## Connections

- Terraform CLI → Plugin Entrypoint: launches
- Plugin Entrypoint → Provider Registration: starts
- Provider Registration → Framework Integration: integrates
- Provider Registration → Shared DNS Config: configures
- Provider Registration → Provider Validation: validates inputs
- Provider Validation → DNS Name Rules: applies naming rules
- Provider Registration → Record Resources: registers
- Record Resources → Record Type Semantics: dispatches to
- Record Resources → State Hashing: uses
- Provider Registration → DNS Data Sources: registers
- DNS Data Sources → DNS Lookup Layer: queries through
- Shared DNS Config → TSIG / GSS-TSIG: supports
- Shared DNS Config → Authoritative DNS Server: configures client for
- Record Resources → Authoritative DNS Server: RFC 2136 UPDATE
- DNS Lookup Layer → Authoritative DNS Server: DNS queries
- TSIG / GSS-TSIG → Authoritative DNS Server: authenticates updates
- Acceptance Environment → Terraform CLI: runs real processes
- Acceptance Environment → Authoritative DNS Server: provisions DNS/Kerberos
- GitHub Actions → Acceptance Environment: executes tests
- GitHub Actions → Registry Documentation: generates
- Provider Registration → Registry Documentation: supplies schemas
