Skip to main content

DomainRecords

Manage DNS records for a Namecheap domain
3 min read

The DomainRecords resource allows you to manage DNS records for a domain registered on Namecheap.

Example Usage#

Basic A Record#

Complete DNS Configuration#

Multiple Environments#

Custom Nameservers#

CNAME Records#

Resource Arguments#

Required Arguments#

  • domain (string, required)
    The purchased domain name on your Namecheap account (e.g., "example.com")

Optional Arguments#

  • domainRecordsId (string, optional)
    Custom identifier for the domain records resource

  • emailType (string, optional)
    Email forwarding type for the domain
    Possible values: NONE, MXE, MX, FWD, OX, GMAIL
    Default: NONE

  • mode (string, optional)
    How to handle existing records
    Possible values:

    • MERGE (default): Merge new records with existing records
    • OVERWRITE: Replace all existing records with new records

    Default: MERGE

  • nameservers (string[], optional)
    Custom nameservers for the domain. When specified, this overrides Namecheap's default nameservers.
    Example: ["ns1.example.com", "ns2.example.com"]

  • records (Record[], optional)
    Array of DNS records to create. See Record Object below.

Record Object#

Each record in the records array supports the following properties:

  • address (string, required)
    The value for the DNS record. Can be an IP address or hostname depending on record type.
    Examples:

    • A record: "192.0.2.1"
    • CNAME record: "example.com"
    • MX record: "mail.example.com"
    • TXT record: "v=spf1 include:_spf.example.com ~all"
  • hostname (string, required)
    The subdomain or hostname for the record. Use "@" for the root domain.
    Examples: "@", "www", "api", "mail"

  • type (string, required)
    The DNS record type
    Possible values: A, AAAA, ALIAS, CAA, CNAME, MX, MXE, NS, TXT, URL, URL301, FRAME

  • mxPref (number, optional)
    MX preference (priority) for the mail server. Lower values have higher priority.
    Required for MX records only
    Typical values: 10, 20, 30

  • ttl (number, optional)
    Time to live in seconds - how long DNS resolvers should cache this record
    Range: 60 to 60000 seconds
    Common values:

    • 300 (5 minutes): For frequently changing records
    • 1800 (30 minutes): For moderately stable records
    • 3600 (1 hour): For stable records
    • 86400 (24 hours): For very stable records

Resource Attributes#

The following attributes are exported by the resource:

  • domain (string)
    The domain name

  • domainRecordsId (string)
    The unique identifier for the domain records resource

  • emailType (string)
    The configured email type

  • mode (string)
    The merge mode used

  • nameservers (string[])
    The configured nameservers

  • records (Record[])
    The configured DNS records

Import#

Existing domain records can be imported using the domain name:

Record Type Reference#

A Record#

Maps a hostname to an IPv4 address.

AAAA Record#

Maps a hostname to an IPv6 address.

CNAME Record#

Creates an alias from one domain name to another.

Note: CNAME records cannot be used for the root domain (@).

MX Record#

Specifies mail servers for the domain.

TXT Record#

Stores text information for various purposes (SPF, DKIM, domain verification).

NS Record#

Delegates a subdomain to different nameservers.

CAA Record#

Specifies which certificate authorities can issue certificates for the domain.

URL/URL301 Records#

Creates URL redirects (Namecheap-specific feature).

Best Practices#

TTL Selection#

  • Development/Testing: 300-600 seconds (5-10 minutes)
  • Staging: 1800 seconds (30 minutes)
  • Production (stable): 3600+ seconds (1+ hours)
  • Before major changes: Lower TTL 24-48 hours before planned changes

Record Organization#

Group related records together:

Mode Selection#

  • OVERWRITE: Use when you want complete control and Pulumi should manage ALL records
  • MERGE: Use when you want to manage specific records while preserving others (e.g., manual records or records managed elsewhere)

Security Considerations#

  • Keep production domains separate from test domains
  • Use appropriate SPF, DKIM, and DMARC records for email security
  • Consider using CAA records to restrict certificate issuance
  • Monitor DNS changes through Pulumi state

Common Patterns#

Multi-Region Setup#

Dynamic Records from Stack Outputs#

Troubleshooting#

Common Errors#

Error: Domain not found

Error: Invalid record type

Error: CNAME conflict

Error: Invalid TTL value

DNS Not Updating#

  1. Check the TTL of the previous record - changes may be cached
  2. Verify the record was actually updated in Namecheap's control panel
  3. Use dig or online DNS checkers to verify propagation
  4. Allow up to 48 hours for complete global propagation (though usually much faster)

Verification#

Check your DNS records after deployment: