Skip to content

feat(domains): validate TXT record content is enclosed in double quotes#412

Open
delfer wants to merge 3 commits into
selectel:masterfrom
delfer:quotes-in-resource_selectel_domains_rrset_v2
Open

feat(domains): validate TXT record content is enclosed in double quotes#412
delfer wants to merge 3 commits into
selectel:masterfrom
delfer:quotes-in-resource_selectel_domains_rrset_v2

Conversation

@delfer

@delfer delfer commented Jul 21, 2026

Copy link
Copy Markdown

Add CustomizeDiff to domains_rrset_v2 resource that validates TXT records have content wrapped in double quotes. Add unit tests for validateTXTRecordContent and acceptance tests for quoted/unquoted TXT and non-TXT record content.

 TF_ACC=1 go test -v -run "DomainsRRSet" ./selectel/       

=== RUN   TestAccDomainsRRSetV2DataSourceBasic
--- PASS: TestAccDomainsRRSetV2DataSourceBasic (79.12s)
=== RUN   TestAccDomainsRRSetV2ImportBasic
--- PASS: TestAccDomainsRRSetV2ImportBasic (8.67s)
=== RUN   TestAccDomainsRRSetV2Basic
--- PASS: TestAccDomainsRRSetV2Basic (81.89s)
=== RUN   TestAccDomainsRRSetV2TXTUnquotedContent
--- PASS: TestAccDomainsRRSetV2TXTUnquotedContent (0.23s)
=== RUN   TestAccDomainsRRSetV2TXTQuotedContent
--- PASS: TestAccDomainsRRSetV2TXTQuotedContent (75.31s)
=== RUN   TestAccDomainsRRSetV2NonTXTUnquotedContent
--- PASS: TestAccDomainsRRSetV2NonTXTUnquotedContent (87.59s)
=== RUN   TestResourceDomainsRRSetV2Schema_HasCustomizeDiff
--- PASS: TestResourceDomainsRRSetV2Schema_HasCustomizeDiff (0.00s)
PASS
ok      github.com/terraform-providers/terraform-provider-selectel/selectel     333.808s

Delfer added 3 commits July 21, 2026 11:11
Add CustomizeDiff to domains_rrset_v2 resource that validates TXT
records have content wrapped in double quotes. Add unit tests for
validateTXTRecordContent and acceptance tests for quoted/unquoted
TXT and non-TXT record content.
…tant

Remove local  variable declarations that shadow the
package-level  defined in
resource_selectel_domains_zone_v2_test.go, fixing linting errors.

var ErrRRSetNotFound = errors.New("rrset not found")

func resourceDomainsRRSetV2CustomizeDiff(_ context.Context, d *schema.ResourceDiff, _ interface{}) error {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем нам _ аргументы в функции? чтобы не ломать сигнатуру?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, сигнатура должна соответствовать schema.CustomizeDiffFunc, чтобы потом передать в атрибут schema.Resource. При этом параметры context.Context и interface{} для валидации не нужны.


func resourceDomainsRRSetV2CustomizeDiff(_ context.Context, d *schema.ResourceDiff, _ interface{}) error {
recordType := d.Get("type").(string)
if recordType != "TXT" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Почему не стал использовать domainsV2.TXT используемый в тестах?
  2. Пользователь может указать lower case: txt?


func validateTXTRecordContent(content string) error {
if len(content) < 2 || content[0] != '"' || content[len(content)-1] != '"' {
return fmt.Errorf("TXT record content must be enclosed in double quotes, got: %q", content)

@milkrage milkrage Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Необходимо добавить CHANGELOG и описать там, что теперь необходимо указывать:
    "\"txt-record-value\"".
  2. Запись контента для TXT записи в формате Multi String, с точки зрения API, возможна?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants