Skip to content

Commit b0ce0a0

Browse files
committed
feat(domain): add record resource
1 parent aa12d5d commit b0ce0a0

15 files changed

+4722
-11
lines changed

.github/workflows/acceptance-tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
- Account
1313
- AppleSilicon
1414
- Baremetal
15+
- DomainRecord
1516
- Instance
1617
- Iot
1718
- K8S
@@ -35,6 +36,7 @@ jobs:
3536
TF_LOG: DEBUG
3637
TF_ACC: 1
3738
TF_UPDATE_CASSETTES: false
39+
TF_TEST_DOMAIN: scaleway-terraform.com
3840
SCW_DEBUG: 0
3941
SCW_ACCESS_KEY: "SCWXXXXXXXXXXXXXFAKE"
4042
SCW_SECRET_KEY: "11111111-1111-1111-1111-111111111111"

.github/workflows/nightly.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Nightly Acceptance Tests
33
on:
44
schedule:
55
# Will run at 00:00 every day
6-
- cron: '0 0 * * *'
6+
- cron: "0 0 * * *"
77

88
jobs:
99
nightly:
@@ -14,6 +14,7 @@ jobs:
1414
- Account
1515
- AppleSilicon
1616
- Baremetal
17+
- DomainRecord
1718
- Instance
1819
- Iot
1920
- K8S
@@ -39,6 +40,7 @@ jobs:
3940
TF_ACC: 1
4041
# Enable recording with the cassette system. By doing so, we ensure that real HTTPS requests are made.
4142
TF_UPDATE_CASSETTES: true
43+
TF_TEST_DOMAIN: scaleway-terraform.com
4244
SCW_DEBUG: 1
4345
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
4446
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ website/node_modules
1515
*.backup
1616
./*.tfstate
1717
.terraform/
18+
test.tf
1819
*.log
1920
*.bak
2021
*~

TESTING.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,22 @@ export TF_UPDATE_CASSETTES=true
3030
make testacc
3131
```
3232

33-
It's also required to have Scaleway environment vars available :
33+
It's also required to have Scaleway environment vars available:
3434

3535
```sh
3636
export SCW_ACCESS_KEY=SCWXXXXXXXXXXXXXXXXX
3737
export SCW_SECRET_KEY=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
3838
export SCW_DEFAULT_PROJECT_ID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
3939
```
4040

41+
For testing the domain API, it will use the first available domain in your domains list. You need to have a valid domain.
42+
43+
You can force the test domain with an environment var:
44+
45+
```sh
46+
export TF_TEST_DOMAIN=your-domain.tld
47+
```
48+
4149
To ease debugging you can also set:
4250
```sh
4351
export TF_LOG=DEBUG
@@ -46,5 +54,5 @@ export SCW_DEBUG=1
4654

4755
Running a single test:
4856
```sh
49-
TF_UPDATE_CASSETTES=true;TF_LOG=DEBUG;SCW_DEBUG=1;TF_ACC=1 go test ./scaleway -v -run=TestAccScalewayDataSourceRDBInstance_Basic -timeout=120m -parallel=10
57+
TF_UPDATE_CASSETTES=true TF_LOG=DEBUG SCW_DEBUG=1 TF_ACC=1 go test ./scaleway -v -run=TestAccScalewayDataSourceRDBInstance_Basic -timeout=120m -parallel=10
5058
```

docs/index.md

+27-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ You can test this config by creating a `test.tf` and run terraform commands from
4040
- Build the infrastructure: `terraform apply`
4141

4242
```hcl
43+
variable "project_id" {
44+
type = string
45+
description = "Your project ID."
46+
}
47+
4348
terraform {
4449
required_providers {
4550
scaleway = {
@@ -50,18 +55,31 @@ terraform {
5055
}
5156
5257
provider "scaleway" {
53-
zone = "fr-par-1"
54-
region = "fr-par"
58+
zone = "fr-par-1"
59+
region = "fr-par"
5560
}
5661
57-
resource "scaleway_instance_ip" "public_ip" {}
62+
resource "scaleway_instance_ip" "public_ip" {
63+
project_id = var.project_id
64+
}
65+
resource "scaleway_instance_ip" "public_ip_backup" {
66+
project_id = var.project_id
67+
}
5868
5969
resource "scaleway_instance_volume" "data" {
70+
project_id = var.project_id
6071
size_in_gb = 30
61-
type = "l_ssd"
72+
type = "l_ssd"
73+
}
74+
75+
resource "scaleway_instance_volume" "data_backup" {
76+
project_id = var.project_id
77+
size_in_gb = 10
78+
type = "l_ssd"
6279
}
6380
6481
resource "scaleway_instance_security_group" "www" {
82+
project_id = var.project_id
6583
inbound_default_policy = "drop"
6684
outbound_default_policy = "accept"
6785
@@ -83,14 +101,15 @@ resource "scaleway_instance_security_group" "www" {
83101
}
84102
85103
resource "scaleway_instance_server" "web" {
86-
type = "DEV1-L"
87-
image = "ubuntu_focal"
104+
project_id = var.project_id
105+
type = "DEV1-L"
106+
image = "ubuntu_focal"
88107
89-
tags = [ "front", "web" ]
108+
tags = ["front", "web"]
90109
91110
ip_id = scaleway_instance_ip.public_ip.id
92111
93-
additional_volume_ids = [ scaleway_instance_volume.data.id ]
112+
additional_volume_ids = [scaleway_instance_volume.data.id]
94113
95114
root_volume {
96115
# The local storage of a DEV1-L instance is 80 GB, subtract 30 GB from the additional l_ssd volume, then the root volume needs to be 50 GB.

docs/resources/domain_record.md

+240
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
---
2+
page_title: "Scaleway: scaleway_domain_record"
3+
description: |-
4+
Manages Scaleway Domain records.
5+
---
6+
7+
# scaleway_domain_record
8+
9+
Creates and manages Scaleway Domain record.
10+
For more information, see [the documentation](https://www.scaleway.com/en/docs/scaleway-dns/).
11+
12+
## Examples
13+
14+
### Basic
15+
16+
```hcl
17+
resource "scaleway_domain_record" "www" {
18+
dns_zone = "domain.tld"
19+
name = "www"
20+
type = "A"
21+
data = "1.2.3.4"
22+
ttl = 3600
23+
}
24+
25+
resource "scaleway_domain_record" "www2" {
26+
dns_zone = "domain.tld"
27+
name = "www"
28+
type = "A"
29+
data = "1.2.3.5"
30+
ttl = 3600
31+
}
32+
33+
resource "scaleway_domain_record" "mx" {
34+
dns_zone = "domain.tld"
35+
name = ""
36+
type = "MX"
37+
data = "mx.online.net."
38+
ttl = 3600
39+
priority = 10
40+
}
41+
42+
resource "scaleway_domain_record" "mx2" {
43+
dns_zone = "domain.tld"
44+
name = ""
45+
type = "MX"
46+
data = "mx-cache.online.net."
47+
ttl = 3600
48+
priority = 20
49+
}
50+
```
51+
52+
### With dynamic records
53+
54+
```hcl
55+
resource "scaleway_domain_record" "geo_ip" {
56+
dns_zone = "domain.tld"
57+
name = "images"
58+
type = "A"
59+
data = "1.2.3.4"
60+
ttl = 3600
61+
62+
geo_ip {
63+
matches {
64+
continents = ["EU"]
65+
countries = ["FR"]
66+
data = "1.2.3.5"
67+
}
68+
69+
matches {
70+
continents = ["NA"]
71+
data = "4.3.2.1"
72+
}
73+
}
74+
}
75+
76+
resource "scaleway_domain_record" "http_service" {
77+
dns_zone = "domain.tld"
78+
name = "app"
79+
type = "A"
80+
data = "1.2.3.4"
81+
ttl = 3600
82+
83+
http_service {
84+
ips = ["1.2.3.5", "1.2.3.6"]
85+
must_contain = "up"
86+
url = "http://mywebsite.com/health"
87+
user_agent = "scw_service_up"
88+
strategy = "hashed"
89+
}
90+
}
91+
92+
resource "scaleway_domain_record" "view" {
93+
dns_zone = "domain.tld"
94+
name = "db"
95+
type = "A"
96+
data = "1.2.3.4"
97+
ttl = 3600
98+
99+
view {
100+
subnet = "100.0.0.0/16"
101+
data = "1.2.3.5"
102+
}
103+
104+
view {
105+
subnet = "100.1.0.0/16"
106+
data = "1.2.3.6"
107+
}
108+
}
109+
110+
resource "scaleway_domain_record" "weighted" {
111+
dns_zone = "domain.tld"
112+
name = "web"
113+
type = "A"
114+
data = "1.2.3.4"
115+
ttl = 3600
116+
117+
weighted {
118+
ip = "1.2.3.5"
119+
weight = 1
120+
}
121+
122+
weighted {
123+
ip = "1.2.3.6"
124+
weight = 2
125+
}
126+
}
127+
```
128+
129+
### Create an instance and add records with the new instance IP
130+
131+
```hcl
132+
variable "project_id" {
133+
type = string
134+
description = "Your project ID."
135+
}
136+
137+
variable "dns_zone" {
138+
type = string
139+
description = "The DNS Zone used for testing records."
140+
}
141+
142+
resource "scaleway_instance_ip" "public_ip" {
143+
project_id = var.project_id
144+
}
145+
146+
resource "scaleway_instance_server" "web" {
147+
project_id = var.project_id
148+
type = "DEV1-S"
149+
image = "ubuntu_focal"
150+
tags = ["front", "web"]
151+
ip_id = scaleway_instance_ip.public_ip.id
152+
153+
root_volume {
154+
size_in_gb = 20
155+
}
156+
}
157+
158+
resource "scaleway_domain_record" "web_A" {
159+
dns_zone = var.dns_zone
160+
name = "web"
161+
type = "A"
162+
data = scaleway_instance_server.web.public_ip
163+
ttl = 3600
164+
}
165+
166+
resource "scaleway_domain_record" "web_cname" {
167+
dns_zone = var.dns_zone
168+
name = "www"
169+
type = "CNAME"
170+
data = "web.${var.dns_zone}."
171+
ttl = 3600
172+
}
173+
174+
resource "scaleway_domain_record" "web_alias" {
175+
dns_zone = var.dns_zone
176+
name = ""
177+
type = "ALIAS"
178+
data = "web.${var.dns_zone}."
179+
ttl = 3600
180+
}
181+
```
182+
183+
## Arguments Reference
184+
185+
The following arguments are supported:
186+
187+
- `dns_zone` - (Required) The DNS Zone of the domain. If the DNS zone doesn't exist, it will be automatically created.
188+
189+
- `keep_empty_zone` - (Optional, default: `false`) When destroying a resource, if only NS records remain and this is set to `false`, the zone will be deleted. Please note, each zone not deleted will [cost you money](https://www.scaleway.com/en/dns/)
190+
191+
- `name` - (Required) The name of the record (can be an empty string for a root record).
192+
193+
- `type` - (Required) The type of the record (`A`, `AAAA`, `MX`, `CNAME`, `ALIAS`, `NS`, `PTR`, `SRV`, `TXT`, `TLSA`, or `CAA`).
194+
195+
- `data` - (Required) The content of the record (an IPv4 for an `A`, a string for a `TXT`...).
196+
197+
- `ttl` - (Optional, default: `3600`) Time To Tive of the record in seconds.
198+
199+
- `priority` - (Optional, default: `0`) The priority of the record (mostly used with an `MX` record)
200+
201+
**Dynamic records:**
202+
203+
- `geo_ip` - (Optional) The Geo IP feature provides DNS resolution, based on the user’s geographical location. You can define a default IP that resolves if no Geo IP rule matches, and specify IPs for each geographical zone. [Documentation and usage example](https://www.scaleway.com/en/docs/scaleway-dns/#-Geo-IP-Records)
204+
- `matches` - (Required) The list of matches. *(Can be more than 1)*
205+
- `countries` - (Optional) List of countries (eg: `FR` for France, `US` for the United States, `GB` for Great Britain...). [List of all countries code](https://api.scaleway.com/domain-private/v2beta1/countries)
206+
- `continents` - (Optional) List of continents (eg: `EU` for Europe, `NA` for North America, `AS` for Asia...). [List of all continents code](https://api.scaleway.com/domain-private/v2beta1/continents)
207+
- `data` (Required) The data of the match result
208+
209+
210+
- `http_service` - (Optional) The DNS service checks the provided URL on the configured IPs and resolves the request to one of the IPs by excluding the ones not responding to the given string to check. [Documentation and usage example](https://www.scaleway.com/en/docs/scaleway-dns/#-Healthcheck-records)
211+
- `ips` - (Required) List of IPs to check
212+
- `must_contain` - (Required) Text to search
213+
- `url` - (Required) URL to match the `must_contain` text to validate an IP
214+
- `user_agent` - (Optional) User-agent used when checking the URL
215+
- `strategy` - (Required) Strategy to return an IP from the IPs list. Can be `random` or `hashed`
216+
217+
218+
- `view` - (Optional) The answer to a DNS request is based on the client’s (resolver) subnet. *(Can be more than 1)* [Documentation and usage example](https://www.scaleway.com/en/docs/scaleway-dns/#-Views-records)
219+
- `subnet` - (Required) The subnet of the view
220+
- `data` - (Required) The data of the view record
221+
222+
223+
- `weighted` - (Optional) You provide a list of IPs with their corresponding weights. These weights are used to proportionally direct requests to each IP. Depending on the weight of a record more or fewer requests are answered with its related IP compared to the others in the list. *(Can be more than 1)* [Documentation and usage example](https://www.scaleway.com/en/docs/scaleway-dns/#-Weight-Records)
224+
- `ip` - (Required) The weighted IP
225+
- `weight` - (Required) The weight of the IP as an integer UInt32.
226+
227+
## Multiple records
228+
229+
Some record types can have multiple `data` with the same `name` (eg: `A`, `AAAA`, `MX`, `NS`...).
230+
You can duplicate a resource `scaleway_domain_record` with the same `name`, the records will be added.
231+
232+
Please note, some record (eg: `CNAME`, Multiple dynamic records of different types...) has to be unique.
233+
234+
## Import
235+
236+
Record can be imported using the `{dns_zone}/{id}`, e.g.
237+
238+
```bash
239+
$ terraform import scaleway_domain_record.www subdomain.domain.tld/11111111-1111-1111-1111-111111111111
240+
```

0 commit comments

Comments
 (0)