Skip to content

Commit bdc2f21

Browse files
authored
feat(tem): TEM domain record fields and tests (#3367)
1 parent 593776e commit bdc2f21

File tree

9 files changed

+772
-557
lines changed

9 files changed

+772
-557
lines changed

docs/resources/tem_domain.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ resource "scaleway_tem_domain" "main" {
3434
resource "scaleway_domain_record" "spf" {
3535
dns_zone = var.domain_name
3636
type = "TXT"
37-
data = "v=spf1 ${scaleway_tem_domain.main.spf_config} -all"
37+
data = scaleway_tem_domain.main.spf_value
3838
}
3939
4040
resource "scaleway_domain_record" "dkim" {
4141
dns_zone = var.domain_name
42-
name = "${scaleway_tem_domain.main.project_id}._domainkey"
42+
name = scaleway_tem_domain.main.dkim_name
4343
type = "TXT"
4444
data = scaleway_tem_domain.main.dkim_config
4545
}
4646
4747
resource "scaleway_domain_record" "mx" {
4848
dns_zone = var.domain_name
4949
type = "MX"
50-
data = "."
50+
data = scaleway_tem_domain.main.mx_config
5151
}
5252
5353
resource "scaleway_domain_record" "dmarc" {
@@ -147,6 +147,12 @@ In addition to all arguments above, the following attributes are exported:
147147

148148
- `dmarc_config` - DMARC record for the domain, as should be recorded in the DNS zone.
149149

150+
- `dkim_name` - DKIM name for the domain, as should be recorded in the DNS zone.
151+
152+
- `spf_value` - Complete SPF record value for the domain, as should be recorded in the DNS zone.
153+
154+
- `mx_config` - MX record configuration for the domain blackhole.
155+
150156
- `smtp_host` - The SMTP host to use to send emails.
151157

152158
- `smtp_port_unsecure` - The SMTP port to use to send emails.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/nats-io/jwt/v2 v2.8.0
3030
github.com/nats-io/nats.go v1.46.1
3131
github.com/robfig/cron/v3 v3.0.1
32-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35
32+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20250929150437-c65b49480cff
3333
github.com/stretchr/testify v1.11.1
3434
golang.org/x/crypto v0.42.0
3535
golang.org/x/sync v0.17.0

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
156156
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
157157
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
158158
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
159-
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
160-
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
161159
github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk=
162160
github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE=
163161
github.com/docker/docker v28.4.0+incompatible h1:KVC7bz5zJY/4AZe/78BIvCnPsLaC9T/zh72xnlrTTOk=
@@ -203,6 +201,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
203201
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
204202
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
205203
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
204+
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
205+
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
206206
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
207207
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
208208
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -456,8 +456,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
456456
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
457457
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
458458
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
459-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35 h1:8xfn1RzeI9yoCUuEwDy08F+No6PcKZGEDOQ6hrRyLts=
460-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35/go.mod h1:47B1d/YXmSAxlJxUJxClzHR6b3T4M1WyCvwENPQNBWc=
459+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20250929150437-c65b49480cff h1:1XC8rVPK4hr2lHdHajSurEV2Orp8eMGQ42vqh4hVX7M=
460+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20250929150437-c65b49480cff/go.mod h1:DVB9HV7nK7TdTRqlpdxw6T0Wxg+aB9xPBEpO3aM2iqQ=
461461
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
462462
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
463463
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
@@ -895,6 +895,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
895895
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
896896
gopkg.in/dnaeon/go-vcr.v3 v3.2.0 h1:Rltp0Vf+Aq0u4rQXgmXgtgoRDStTnFN83cWgSGSoRzM=
897897
gopkg.in/dnaeon/go-vcr.v3 v3.2.0/go.mod h1:2IMOnnlx9I6u9x+YBsM3tAMx6AlOxnJ0pWxQAzZ79Ag=
898+
gopkg.in/dnaeon/go-vcr.v4 v4.0.5 h1:I0hpTIvD5rII+8LgYGrHMA2d4SQPoL6u7ZvJakWKsiA=
899+
gopkg.in/dnaeon/go-vcr.v4 v4.0.5/go.mod h1:dRos81TkW9C1WJt6tTaE+uV2Lo8qJT3AG2b35+CB/nQ=
898900
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
899901
gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4=
900902
gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

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)