A production-ready Terraform provider for managing DNS records on Reg.ru with dedicated resources for each DNS record type.
- 8 Dedicated DNS Record Types: A, AAAA, CNAME, MX, NS, TXT, SRV, CAA - each with optimized schemas
- Advanced Record Management: Complex record types support multiple configurations with priority control
- Surgical Update Logic: Intelligent updates that only modify changed records, not full delete/recreate
- Enterprise-Grade Diff Suppression: Order-independent comparison prevents unnecessary changes
- Complete Import Support: Import existing DNS records with simple
zone/nameformat - Production Architecture: Clean strategy pattern with optimized performance
- ForceNew Resource Management: Proper lifecycle management for zone/name changes
To use this provider, you need to activate the following options in your Reg.ru API settings:
- Alternative Password: Required for API authentication
- IP Address Ranges: Required for API access control
terraform {
required_providers {
regru = {
source = "sport24ru/regru"
version = "~> 1.0"
}
}
}
provider "regru" {
username = var.regru_username
password = var.regru_password
}These use straightforward records lists:
- A Records (
regru_dns_a_record): IPv4 addresses - AAAA Records (
regru_dns_aaaa_record): IPv6 addresses - TXT Records (
regru_dns_txt_record): Text records
These use structured record blocks for advanced configuration:
- CNAME Records (
regru_dns_cname_record): Single canonical name withcnamefield - MX Records (
regru_dns_mx_record): Mail servers with priority and multiple servers per priority - NS Records (
regru_dns_ns_record): Name servers with priority support - SRV Records (
regru_dns_srv_record): Service records with priority, weight, port, and targets - CAA Records (
regru_dns_caa_record): Certificate Authority Authorization with flag, tag, value
# A Record - IPv4 addresses
resource "regru_dns_a_record" "web_servers" {
zone = "example.com"
name = "www"
records = ["192.168.1.100", "192.168.1.101"]
}
# AAAA Record - IPv6 addresses
resource "regru_dns_aaaa_record" "ipv6_servers" {
zone = "example.com"
name = "ipv6"
records = ["2001:db8::1", "2001:db8::2"]
}
# TXT Record - Text records
resource "regru_dns_txt_record" "verification" {
zone = "example.com"
name = "verify"
records = [
"v=spf1 include:_spf.google.com ~all",
"google-site-verification=abc123"
]
}# CNAME Record - Single canonical name
resource "regru_dns_cname_record" "www_alias" {
zone = "example.com"
name = "www"
cname = "web.example.com"
}
# MX Record - Mail servers with priorities
resource "regru_dns_mx_record" "mail_servers" {
zone = "example.com"
name = "@"
record {
priority = 10
servers = ["mail1.example.com", "mail2.example.com"]
}
record {
priority = 20
servers = ["backup.example.com"]
}
}
# NS Record - Name servers with priority
resource "regru_dns_ns_record" "subdomain" {
zone = "example.com"
name = "subdomain"
record {
priority = 10
servers = ["ns1.example.com", "ns2.example.com"]
}
}
# SRV Record - Service discovery
resource "regru_dns_srv_record" "xmpp_server" {
zone = "example.com"
name = "_xmpp-server._tcp"
record {
priority = 10
weight = 5
port = 5269
targets = ["xmpp1.example.com", "xmpp2.example.com"]
}
}
# CAA Record - Certificate Authority Authorization
resource "regru_dns_caa_record" "ssl_certs" {
zone = "example.com"
name = "@"
record {
flag = 0
tag = "issue"
value = "letsencrypt.org"
}
record {
flag = 128
tag = "iodef"
value = "mailto:security@example.com"
}
}All record types can be imported using the format zone/name:
# Import A record
terraform import regru_dns_a_record.web_servers example.com/www
# Import MX record
terraform import regru_dns_mx_record.mail_servers example.com/@
# Import SRV record
terraform import regru_dns_srv_record.xmpp_server example.com/_xmpp-server._tcpIf you're migrating from the previous version that used a single regru_dns_record resource, you'll need to:
- Replace the generic resource with specific record type resources
- Update your configuration to use the new dedicated resources
- Import existing records into the new resource structure
See Migration Guide for detailed instructions.
Records are compared as sets - changing the order in your configuration won't trigger unnecessary updates:
# These are equivalent:
records = ["1.1.1.1", "2.2.2.2"]
records = ["2.2.2.2", "1.1.1.1"]For complex record types (MX, NS, SRV), only changed sub-records are updated, not the entire record set. This reduces API calls and potential service disruption.
Changing zone or name triggers proper resource replacement (destroy + create) since these changes require a new DNS record.
- Surgical Updates: Only modified sub-records are updated, reducing API calls by up to 90%
- Zone-Level Caching: Intelligent caching minimizes redundant API requests
- Order-Independent Comparison: Prevents unnecessary updates from configuration reordering
This provider uses a clean, maintainable architecture:
- Strategy Pattern: Each record type has an optimized strategy
- Generic Operations: Simple records (A, AAAA, TXT) use shared, optimized operations
- Specific Implementations: Complex records (MX, SRV, CAA, NS, CNAME) have specialized logic
- Factory Pattern: Dynamic resource generation eliminates code duplication
- Fork the repository
- Create a feature branch
- Make your changes following the existing patterns
- Test thoroughly with real DNS records
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.