Terraform is an infrastructure as code tool that lets you build, change, and version infrastructure safely and efficiently. This includes low-level components like compute instances, storage, and networking; and high-level components like DNS entries and SaaS features.
One of the requirements to use the Terrafrom plugin for ClouDNS is to have access to our HTTP API. All our Premium DNS and DDoS Protected DNS plans include access to the HTTP API and can be used to manage your zones with OctoDNS.
Create a folder named Terraform and open it. In the Terraform folder create two new folders, one named "zone" and one named "records". Open the "zone" folder. There you need to create two text files with tf extensions. The first file is provider.tf. In this file, you need to place the text shown below and replace the API credentials with the API credentials of the user or sub-user you have created. You can find more information here.
terraform {
required_providers {
cloudns = {
source = "Cloudns/cloudns"
version = "1.0.1"
}
}
}
provider "cloudns" {
auth_id = XXXX
password = "XXXXXXX"
rate_limit = 10
}
The second file you need to create in this folder is resource.tf. In this file you need to add the zones you want to be added to your account. An example of how a zone should be added in the file is shown bellow.
#adding master DNS zone
resource "cloudns_dns_zone" "zone-test" {
domain = "testzone.com"
type = "master"
}
#adding slave DNS zone
resource "cloudns_dns_zone" "zone-test2" {
domain = "slavezoneterraform.com"
type = "slave"
master = "1.2.3.6"
}
#adding geo DNS zone
resource "cloudns_dns_zone" "zone-test3" {
domain = "geozone.com"
type = "geodns"
}
#adding parked DNS zone
resource "cloudns_dns_zone" "zone-test4" {
domain = "parkedzone.com"
type = "parked"
}
#adding reverse master DNS zone
resource "cloudns_dns_zone" "zone-test5" {
domain = "1.2.3.5.in-addr.arpa"
type = "master"
}
#adding reverse slave DNS zone
resource "cloudns_dns_zone" "zone-test2" {
domain = "1.2.3.5.in-addr.arpa"
type = "slave"
master = "1.2.3.6"
Save the file. In order to apply the changes you need to run these two commands:
The terraform init command initializes a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. It is safe to run this command multiple times.
terraform init
The terraform apply automatically generates a new plan and prompts you to approve it
terraform apply
See the changes that will be made and approve them by writing yes and clicking Enter.
#adding A record
resource "cloudns_dns_record" "A-record-test" {
name = "A2record"
zone = "testzone.com"
type = "A"
value = "1.2.3.5"
ttl = "3600"
}
#adding CNAME record
resource "cloudns_dns_record" "CNAME-record-test" {
name = "CNAME"
zone = "geozone.com"
type = "CNAME"
value = "somedomain.com"
ttl = "3600"
}
If the zone is geodns, you can add the "geodnslocation" parameter to specify a location for the records that support it. You can find all GeoDNS locations by using this API method. You can find all of the parameters for the records at this link.
Save the file. In order to apply the changes you need to run again these two commands:
terraform init
terraform apply
See the changes that will be made and approve them by writing yes and clicking Enter.
After these steps, your zones and records should be added to your ClouDNS account. Note that at the moment with ClouDNS Terraform, you can only create zones and add or modify records in them. If you have difficulties, you can contact us at any time.