Skip to content

namecheap.domain-records resource

Description

DomainRecords manages the host DNS records of a Namecheap domain, together with the domain's email type. Namecheap has no per-record API: every write is a full SetHosts of the domain's record set and every read a full GetHosts, so this resource owns a set of records rather than a single one. The mode decides how it shares the domain with records it does not define. In overwrite mode it owns the whole record set -- a write replaces every record, and a read reports them all, so a record added elsewhere is drift the resource removes. In merge mode it owns only the records it lists -- a write reads the live set, swaps its own records, and writes the union back, leaving every other record in place. The domain identifies the resource; changing it replaces the resource.

Source: internal/service/domain/records_rsrc.go:27

Example usage:

imports: {
  namecheap: 'github.com/cloudboss/unobin-library-namecheap'
}

resources: {
  example: namecheap.domain-records {
    # Set input fields here.
  }
}

Inputs

domain

string

required

mode

string

default MERGE

email-type

optional(string)

records

list(object)
list(
  object({
    hostname: string
    type: string
    address: string
    mx-pref: optional(integer)
    ttl: optional(integer)
  })
)

Input Constraints

Domain rules

domain is required.

Rule logic
Require
@core.length(input.domain) >= 1

Mode rules

mode must be MERGE or OVERWRITE.

Rule logic
Require
input.mode == 'MERGE'
|| input.mode == 'OVERWRITE'

Email type rules

email-type must be one of NONE, MXE, MX, FWD, OX, or GMAIL.

Rule logic
When
input.email-type != null
Require
input.email-type == 'NONE'
|| input.email-type == 'MXE'
|| input.email-type == 'MX'
|| input.email-type == 'FWD'
|| input.email-type == 'OX'
|| input.email-type == 'GMAIL'

Records rules

a record type must be a valid Namecheap record type.

Rule logic
For each
input.records
Require
@each.value.type == 'A'
|| @each.value.type == 'AAAA'
|| @each.value.type == 'ALIAS'
|| @each.value.type == 'CAA'
|| @each.value.type == 'CNAME'
|| @each.value.type == 'MX'
|| @each.value.type == 'MXE'
|| @each.value.type == 'NS'
|| @each.value.type == 'TXT'
|| @each.value.type == 'URL'
|| @each.value.type == 'URL301'
|| @each.value.type == 'FRAME'

a record ttl must be between 60 and 60000.

Rule logic
For each
input.records
When
@each.value.ttl != null
Require
(@each.value.ttl == null || @each.value.ttl >= 60)
&& (@each.value.ttl == null || @each.value.ttl <= 60000)

a record mx-pref must be between 0 and 255.

Rule logic
For each
input.records
When
@each.value.mx-pref != null
Require
(@each.value.mx-pref == null || @each.value.mx-pref >= 0)
&& (@each.value.mx-pref == null || @each.value.mx-pref <= 255)

Outputs

domain

string

mode

string

email-type

string

records

list(object)
list(
  object({
    hostname: string
    type: string
    address: string
  })
)