Skip to content

Commit 31214f3

Browse files
committed
feat(tem): add new domain record fields for simplified DNS configuration
1 parent fe9a05f commit 31214f3

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
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.

internal/services/tem/domain.go

Lines changed: 33 additions & 3 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,27 @@ 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)
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+
// TODO: These fields will be available in a future SDK version
272+
// DKIM, SPF, and MX records will be added to DomainRecords
273+
_ = d.Set("dkim_name", "")
274+
_ = d.Set("spf_value", "")
275+
_ = d.Set("mx_config", "")
249276
} else {
250277
_ = d.Set("dmarc_name", "")
251278
_ = d.Set("dmarc_config", "")
279+
_ = d.Set("dkim_name", "")
280+
_ = d.Set("spf_value", "")
281+
_ = d.Set("mx_config", "")
252282
}
253283

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

internal/services/tem/domain_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ func TestAccDomain_Basic(t *testing.T) {
3737
isDomainPresent(tt, "scaleway_tem_domain.cr01"),
3838
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", domainName),
3939
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
40-
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc.terraform-rs"),
40+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_name"),
41+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dkim_name"),
42+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "spf_value"),
43+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "mx_config"),
4144
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "last_error", ""), // last_error is deprecated
4245
acctest.CheckResourceAttrUUID("scaleway_tem_domain.cr01", "id"),
4346
),
@@ -107,7 +110,10 @@ func TestAccDomain_Autoconfig(t *testing.T) {
107110
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", subDomainName+"."+domainNameValidation),
108111
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "autoconfig", "true"),
109112
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
110-
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc"+"."+subDomainName),
113+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_name"),
114+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dkim_name"),
115+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "spf_value"),
116+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "mx_config"),
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"),
@@ -147,7 +153,10 @@ func TestAccDomain_AutoconfigUpdate(t *testing.T) {
147153
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", subDomainName+"."+domainNameValidation),
148154
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "autoconfig", "false"),
149155
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
150-
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc"+"."+subDomainName),
156+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_name"),
157+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dkim_name"),
158+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "spf_value"),
159+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "mx_config"),
151160
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "last_error", ""), // last_error is deprecated
152161
acctest.CheckResourceAttrUUID("scaleway_tem_domain.cr01", "id"),
153162
),

templates/resources/tem_domain.md.tmpl

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.

0 commit comments

Comments
 (0)