Skip to content

Commit ba7d654

Browse files
committed
feat(tem): add dkim, spf and mx record fields for domain resource
1 parent 600a290 commit ba7d654

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

internal/services/tem/domain.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ func ResourceDomain() *schema.Resource {
109109
Computed: true,
110110
Description: "DMARC record for the domain, as should be recorded in the DNS zone",
111111
},
112+
"dkim_name": {
113+
Type: schema.TypeString,
114+
Computed: true,
115+
Description: "DKIM name for the domain, as should be recorded in the DNS zone",
116+
},
117+
"spf_value": {
118+
Type: schema.TypeString,
119+
Computed: true,
120+
Description: "Complete SPF record value for the domain, as should be recorded in the DNS zone",
121+
},
122+
"mx_config": {
123+
Type: schema.TypeString,
124+
Computed: true,
125+
Description: "MX record configuration for the domain blackhole",
126+
},
112127
"smtp_host": {
113128
Type: schema.TypeString,
114129
Computed: true,
@@ -243,12 +258,36 @@ func ResourceDomainRead(ctx context.Context, d *schema.ResourceData, m any) diag
243258
_ = d.Set("spf_config", domain.SpfConfig)
244259
_ = d.Set("dkim_config", domain.DkimConfig)
245260

246-
if domain.Records != nil && domain.Records.Dmarc != nil {
247-
_ = d.Set("dmarc_name", domain.Records.Dmarc.Name)
248-
_ = d.Set("dmarc_config", domain.Records.Dmarc.Value)
249-
} else {
250-
_ = d.Set("dmarc_name", "")
251-
_ = d.Set("dmarc_config", "")
261+
if domain.Records != nil {
262+
// DMARC
263+
if domain.Records.Dmarc != nil {
264+
_ = d.Set("dmarc_name", domain.Records.Dmarc.Name)
265+
_ = d.Set("dmarc_config", domain.Records.Dmarc.Value)
266+
} else {
267+
_ = d.Set("dmarc_name", "")
268+
_ = d.Set("dmarc_config", "")
269+
}
270+
271+
// DKIM
272+
if domain.Records.Dkim != nil {
273+
_ = d.Set("dkim_name", domain.Records.Dkim.Name)
274+
} else {
275+
_ = d.Set("dkim_name", "")
276+
}
277+
278+
// SPF
279+
if domain.Records.Spf != nil {
280+
_ = d.Set("spf_value", domain.Records.Spf.Value)
281+
} else {
282+
_ = d.Set("spf_value", "")
283+
}
284+
285+
// MX
286+
if domain.Records.Mx != nil {
287+
_ = d.Set("mx_config", domain.Records.Mx.Value)
288+
} else {
289+
_ = d.Set("mx_config", "")
290+
}
252291
}
253292

254293
_ = d.Set("smtp_host", tem.SMTPHost)

internal/services/tem/domain_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ func TestAccDomain_Basic(t *testing.T) {
3636
Check: resource.ComposeTestCheckFunc(
3737
isDomainPresent(tt, "scaleway_tem_domain.cr01"),
3838
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", domainName),
39-
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
40-
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc.terraform-rs"),
39+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_config", "v=DMARC1; p=none"),
40+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", regexp.MustCompile(`^_dmarc\.terraform-rs\.test\.local\.$`)),
41+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "dkim_name", regexp.MustCompile(`^[a-f0-9-]+\._domainkey\.terraform-rs\.test\.local\.$`)),
42+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "spf_value", regexp.MustCompile(`^v=spf1 include:terraform-rs\.test\.local -all$`)),
43+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "mx_config", "10 blackhole.tem.scaleway.com."),
4144
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "last_error", ""), // last_error is deprecated
4245
acctest.CheckResourceAttrUUID("scaleway_tem_domain.cr01", "id"),
4346
),
@@ -106,8 +109,11 @@ func TestAccDomain_Autoconfig(t *testing.T) {
106109
isDomainPresent(tt, "scaleway_tem_domain.cr01"),
107110
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", subDomainName+"."+domainNameValidation),
108111
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "autoconfig", "true"),
109-
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
110-
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc"+"."+subDomainName),
112+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_config", "v=DMARC1; p=none"),
113+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", regexp.MustCompile(`^_dmarc\.`+regexp.QuoteMeta(subDomainName+"."+domainNameValidation)+`\.$`)),
114+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "dkim_name", regexp.MustCompile(`^[a-f0-9-]+\._domainkey\.`+regexp.QuoteMeta(subDomainName+"."+domainNameValidation)+`\.$`)),
115+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "spf_value", regexp.MustCompile(`^v=spf1 include:`+regexp.QuoteMeta(subDomainName+"."+domainNameValidation)+` -all$`)),
116+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "mx_config", "10 blackhole.tem.scaleway.com."),
111117
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "last_error", ""), // last_error is deprecated
112118
acctest.CheckResourceAttrUUID("scaleway_tem_domain.cr01", "id"),
113119
resource.TestCheckResourceAttr("scaleway_tem_domain_validation.valid", "validated", "true"),
@@ -146,8 +152,11 @@ func TestAccDomain_AutoconfigUpdate(t *testing.T) {
146152
isDomainPresent(tt, "scaleway_tem_domain.cr01"),
147153
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", subDomainName+"."+domainNameValidation),
148154
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "autoconfig", "false"),
149-
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
150-
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc"+"."+subDomainName),
155+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_config", "v=DMARC1; p=none"),
156+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", regexp.MustCompile(`^_dmarc\.`+regexp.QuoteMeta(subDomainName+"."+domainNameValidation)+`\.$`)),
157+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "dkim_name", regexp.MustCompile(`^[a-f0-9-]+\._domainkey\.`+regexp.QuoteMeta(subDomainName+"."+domainNameValidation)+`\.$`)),
158+
resource.TestMatchResourceAttr("scaleway_tem_domain.cr01", "spf_value", regexp.MustCompile(`^v=spf1 include:`+regexp.QuoteMeta(subDomainName+"."+domainNameValidation)+` -all$`)),
159+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "mx_config", "10 blackhole.tem.scaleway.com."),
151160
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "last_error", ""), // last_error is deprecated
152161
acctest.CheckResourceAttrUUID("scaleway_tem_domain.cr01", "id"),
153162
),

0 commit comments

Comments
 (0)