Skip to content

Commit 47475f7

Browse files
committed
docs: how to import existing zones and records
1 parent ca96757 commit 47475f7

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,82 @@ output "hostingde_record" {
4545
}
4646
```
4747

48+
### Importing existing zones and records
49+
#### Zones
50+
- Create `*.tf` files containing the existing zone and records you'd like to import
51+
- Go to https://secure.hosting.de/dns/ then click "Show details" on the zone you'd like to import
52+
- Copy the `ZONE_CONFIG_ID` from the URL: https://secure.hosting.de/dns/zones/id/$ZONE_CONFIG_ID/edit
53+
- Import the `hostingde_zone` resouce using:
54+
```shell
55+
terraform import hostingde_zone.your_zone_name $ZONE_CONFIG_ID
56+
```
57+
58+
#### Records
59+
- Importing records is a little more involved, let's go:
60+
- Write a shell function to prepare `curl` JSON data (this assumes you have your
61+
API token set in the environment and that you replace `$ZONE_CONFIG_ID` with
62+
the ID from above)
63+
```shell
64+
generate_post_data()
65+
{
66+
cat <<EOF
67+
{
68+
"authToken": "$HOSTINGDE_AUTH_TOKEN",
69+
"filter": {
70+
"field": "zoneConfigId",
71+
"value": "$ZONE_CONFIG_ID"
72+
},
73+
"limit": 10,
74+
"page": 1,
75+
"sort": {
76+
"field": "recordName",
77+
"order": "asc"
78+
}
79+
}
80+
EOF
81+
}
82+
```
83+
- Do the curl POST request to get all DNS record IDs of that zone
84+
```shell
85+
curl \
86+
-H "Accept: application/json" \
87+
-H "Content-Type:application/json" \
88+
-X POST \
89+
-d "$(generate_post_data)" \
90+
https://secure.hosting.de/api/dns/v1/json/recordsFind
91+
```
92+
- Example response:
93+
```
94+
{
95+
"errors": [
96+
],
97+
"metadata": {
98+
"clientTransactionId": "",
99+
"serverTransactionId": "20230411151239132-dnsrobot-robots1-26486-0"
100+
},
101+
"response": {
102+
"data": [
103+
{
104+
"accountId": "ACCOUNT_ID",
105+
"addDate": "2023-02-03T13:33:26Z",
106+
"comments": "",
107+
"content": "\"v=DMARC1; p=reject;\"",
108+
"id": "RECORD_ID",
109+
"lastChangeDate": "2023-02-03T13:33:26Z",
110+
"name": "_dmarc.your.domain",
111+
"priority": null,
112+
"recordTemplateId": null,
113+
"ttl": 3600,
114+
"type": "TXT",
115+
"zoneConfigId": "ZONE_CONFIG_ID"
116+
},
117+
...
118+
```
119+
- One by one, import the records:
120+
```shell
121+
terraform import hostingde_record.your_record_name $RECORD_ID
122+
```
123+
48124
# Development and testing
49125
Prepare Terraform for local provider install
50126
```shell
@@ -79,7 +155,7 @@ export HOSTINGDE_AUTH_TOKEN=YOUR-API-TOKEN
79155
make testacc
80156
```
81157

82-
Then, navigate to the `example` directory.
158+
Then, navigate to the `example` directory.
83159

84160
```shell
85161
cd example

0 commit comments

Comments
 (0)