Skip to content

Commit 943b969

Browse files
authored
feat(tem): add support for autoconfig (#2726)
* add argument autoconfig in domain resource * feat(tem): add autoconfig argument in resource domain * add update * feat(tem): update casse autoconfig * feat(tem): update casse autoconfig * add autoconfig in domain validation * fix(tem): add indentation in doc
1 parent ed1abf5 commit 943b969

7 files changed

+3007
-1861
lines changed

docs/resources/tem_domain.md

+17
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ resource "scaleway_domain_record" "dmarc" {
5858
}
5959
```
6060

61+
### Automatically Configure DNS Settings for Your Domain
62+
63+
```terraform
64+
variable "domain_name" {
65+
type = string
66+
}
67+
68+
resource "scaleway_tem_domain" "main" {
69+
name = var.domain_name
70+
accept_tos = true
71+
autoconfig = true
72+
}
73+
74+
```
75+
6176
### Configuring GitLab Project Variables
6277

6378
```terraform
@@ -101,6 +116,8 @@ The following arguments are supported:
101116

102117
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the domain is associated with.
103118

119+
- `autoconfig` - (Defaults to `false`) Automatically configures DNS settings for the domain, simplifying the setup process by applying predefined configurations.
120+
104121
## Attributes Reference
105122

106123
In addition to all arguments above, the following attributes are exported:

internal/services/tem/domain.go

+31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func ResourceDomain() *schema.Resource {
1919
return &schema.Resource{
2020
CreateContext: ResourceDomainCreate,
2121
ReadContext: ResourceDomainRead,
22+
UpdateContext: ResourceDomainUpdate,
2223
DeleteContext: ResourceDomainDelete,
2324
Importer: &schema.ResourceImporter{
2425
StateContext: schema.ImportStatePassthroughContext,
@@ -50,6 +51,12 @@ func ResourceDomain() *schema.Resource {
5051
return warnings, errs
5152
},
5253
},
54+
"autoconfig": {
55+
Type: schema.TypeBool,
56+
Optional: true,
57+
Default: false,
58+
Description: "Enable automatic configuration options for the domain",
59+
},
5360
"status": {
5461
Type: schema.TypeString,
5562
Computed: true,
@@ -192,6 +199,7 @@ func ResourceDomainCreate(ctx context.Context, d *schema.ResourceData, m interfa
192199
ProjectID: d.Get("project_id").(string),
193200
DomainName: d.Get("name").(string),
194201
AcceptTos: d.Get("accept_tos").(bool),
202+
Autoconfig: d.Get("autoconfig").(bool),
195203
}, scw.WithContext(ctx))
196204
if err != nil {
197205
return diag.FromErr(err)
@@ -222,6 +230,7 @@ func ResourceDomainRead(ctx context.Context, d *schema.ResourceData, m interface
222230

223231
_ = d.Set("name", domain.Name)
224232
_ = d.Set("accept_tos", true)
233+
_ = d.Set("autoconfig", domain.Autoconfig)
225234
_ = d.Set("status", domain.Status)
226235
_ = d.Set("created_at", types.FlattenTime(domain.CreatedAt))
227236
_ = d.Set("next_check_at", types.FlattenTime(domain.NextCheckAt))
@@ -246,6 +255,28 @@ func ResourceDomainRead(ctx context.Context, d *schema.ResourceData, m interface
246255
return nil
247256
}
248257

258+
func ResourceDomainUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
259+
api, region, id, err := NewAPIWithRegionAndID(m, d.Id())
260+
if err != nil {
261+
return diag.FromErr(err)
262+
}
263+
264+
if d.HasChange("autoconfig") {
265+
autoconfig := d.Get("autoconfig").(bool)
266+
267+
_, err = api.UpdateDomain(&tem.UpdateDomainRequest{
268+
Region: region,
269+
DomainID: id,
270+
Autoconfig: &autoconfig,
271+
})
272+
if err != nil {
273+
return diag.FromErr(err)
274+
}
275+
}
276+
277+
return ResourceDomainRead(ctx, d, m)
278+
}
279+
249280
func ResourceDomainDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
250281
api, region, id, err := NewAPIWithRegionAndID(m, d.Id())
251282
if err != nil {

internal/services/tem/domain_test.go

+91
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,97 @@ func TestAccDomain_Tos(t *testing.T) {
7070
})
7171
}
7272

73+
func TestAccDomain_Autoconfig(t *testing.T) {
74+
tt := acctest.NewTestTools(t)
75+
defer tt.Cleanup()
76+
77+
resource.ParallelTest(t, resource.TestCase{
78+
PreCheck: func() { acctest.PreCheck(t) },
79+
ProviderFactories: tt.ProviderFactories,
80+
CheckDestroy: isDomainDestroyed(tt),
81+
Steps: []resource.TestStep{
82+
{
83+
Config: fmt.Sprintf(`
84+
resource scaleway_tem_domain cr01 {
85+
name = "%s"
86+
accept_tos = true
87+
autoconfig = true
88+
}
89+
90+
resource scaleway_tem_domain_validation valid {
91+
domain_id = scaleway_tem_domain.cr01.id
92+
region = scaleway_tem_domain.cr01.region
93+
timeout = 3600
94+
}
95+
96+
`, domainNameValidation),
97+
Check: resource.ComposeTestCheckFunc(
98+
isDomainPresent(tt, "scaleway_tem_domain.cr01"),
99+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", domainNameValidation),
100+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "autoconfig", "true"),
101+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
102+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc"),
103+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "last_error", ""), // last_error is deprecated
104+
acctest.CheckResourceAttrUUID("scaleway_tem_domain.cr01", "id"),
105+
resource.TestCheckResourceAttr("scaleway_tem_domain_validation.valid", "validated", "true"),
106+
),
107+
},
108+
},
109+
})
110+
}
111+
112+
func TestAccDomain_AutoconfigUpdate(t *testing.T) {
113+
tt := acctest.NewTestTools(t)
114+
defer tt.Cleanup()
115+
116+
resource.ParallelTest(t, resource.TestCase{
117+
PreCheck: func() { acctest.PreCheck(t) },
118+
ProviderFactories: tt.ProviderFactories,
119+
CheckDestroy: isDomainDestroyed(tt),
120+
Steps: []resource.TestStep{
121+
{
122+
Config: fmt.Sprintf(`
123+
resource scaleway_tem_domain cr01 {
124+
name = "%s"
125+
accept_tos = true
126+
autoconfig = false
127+
}
128+
129+
`, domainNameValidation),
130+
Check: resource.ComposeTestCheckFunc(
131+
isDomainPresent(tt, "scaleway_tem_domain.cr01"),
132+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "name", domainNameValidation),
133+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "autoconfig", "false"),
134+
resource.TestCheckResourceAttrSet("scaleway_tem_domain.cr01", "dmarc_config"),
135+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "dmarc_name", "_dmarc"),
136+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "last_error", ""), // last_error is deprecated
137+
acctest.CheckResourceAttrUUID("scaleway_tem_domain.cr01", "id"),
138+
),
139+
},
140+
{
141+
Config: fmt.Sprintf(`
142+
resource scaleway_tem_domain cr01 {
143+
name = "%s"
144+
accept_tos = true
145+
autoconfig = true
146+
}
147+
148+
resource scaleway_tem_domain_validation valid {
149+
domain_id = scaleway_tem_domain.cr01.id
150+
region = scaleway_tem_domain.cr01.region
151+
timeout = 3600
152+
}
153+
`, domainNameValidation),
154+
Check: resource.ComposeTestCheckFunc(
155+
isDomainPresent(tt, "scaleway_tem_domain.cr01"),
156+
resource.TestCheckResourceAttr("scaleway_tem_domain.cr01", "autoconfig", "true"),
157+
resource.TestCheckResourceAttr("scaleway_tem_domain_validation.valid", "validated", "true"),
158+
),
159+
},
160+
},
161+
})
162+
}
163+
73164
func isDomainPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
74165
return func(state *terraform.State) error {
75166
rs, ok := state.RootModule().Resources[n]

internal/services/tem/domain_validation_test.go

+2-25
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,15 @@ func TestAccDomainValidation_Validation(t *testing.T) {
5454
resource scaleway_tem_domain cr01 {
5555
name = "%s"
5656
accept_tos = true
57-
}
58-
59-
resource "scaleway_domain_record" "spf" {
60-
dns_zone = "%s"
61-
type = "TXT"
62-
data = "v=spf1 ${scaleway_tem_domain.cr01.spf_config} -all"
63-
}
64-
resource "scaleway_domain_record" "dkim" {
65-
dns_zone = "%s"
66-
name = "${scaleway_tem_domain.cr01.project_id}._domainkey"
67-
type = "TXT"
68-
data = scaleway_tem_domain.cr01.dkim_config
69-
}
70-
resource "scaleway_domain_record" "mx" {
71-
dns_zone = "%s"
72-
type = "MX"
73-
data = "."
74-
}
75-
76-
resource "scaleway_domain_record" "dmarc" {
77-
dns_zone = "%s"
78-
name = scaleway_tem_domain.cr01.dmarc_name
79-
type = "TXT"
80-
data = scaleway_tem_domain.cr01.dmarc_config
57+
autoconfig = true
8158
}
8259
8360
resource scaleway_tem_domain_validation valid {
8461
domain_id = scaleway_tem_domain.cr01.id
8562
region = scaleway_tem_domain.cr01.region
8663
timeout = 3600
8764
}
88-
`, domainNameValidation, domainNameValidation, domainNameValidation, domainNameValidation, domainNameValidation),
65+
`, domainNameValidation),
8966
Check: resource.ComposeTestCheckFunc(
9067
resource.TestCheckResourceAttr("scaleway_tem_domain_validation.valid", "validated", "true"),
9168
),

0 commit comments

Comments
 (0)