Zone management with OpenTofu

OpenTofu is a Terraform fork, created as an initiative of Gruntwork, Spacelift, Harness, Env0, Scalr, and others, in response to HashiCorp’s switch from an open-source license to the BUSL

One of the requirements to use the OpenTofu 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.

What are the differences between OpenTofu and Terraform?

On the technical level, OpenTofu is very similar feature-wise to Terraform. In the future, the projects feature sets will diverge. The other main difference is that OpenTofu is open-source, and it's goal is to be driven in a collaborative way with no single company being able to dictate the roadmap.

Here are the steps for the installation and configuration of the module:

  1. First, you need to download and install OpenTofu from here
  2. Next, you need to create an API user or sub-user from your Cloudns account. This can be done from your API & Reseller page here
  3. Create a folder named Opentofu and open it. In the Opentofu 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
    }
    
    
  4. 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 = "slavezonetofu.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"
    
  5. Save the file. In order to apply the changes you need to run these two commands:

    • The tofu init command initializes a working directory containing OpenTofu configuration files. This is the first command that should be run after writing a new OpenTofu configuration or cloning an existing one from version control. It is safe to run this command multiple times.

      tofu init

    • The tofu apply automatically generates a new plan and prompts you to approve it

      tofu apply

    • See the changes that will be made and approve them by writing yes and clicking Enter.

  6. Open the folder "records". There create also the same provider.tf file as before.
  7. Create a resource.tf file and there you should write the records you want to add or modify in the zone. Here are some examples of how to add records.
    
    #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.

  8. Save the file. In order to apply the changes you need to run again these two commands:

    tofu init

    tofu 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 OpenTofu, you can only create zones and add or modify records in them. If you have difficulties, you can contact us at any time.


Last modified: 2024-06-13
Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more