Terraform with OneFuse: DNS

Terraform

In this article we are going to walk through using OneFuse to create DNS records within a Terraform configuration.  To do this we will create a new Terraform configuration that uses the OneFuse provider data source and resource for the DNS policy we created as part of “Creating a OneFuse DNS Policy”.

By the end of this article, we will have created a Terraform configuration that calls OneFuse and registers a host record within the supplied DNS Zone.  While this is simple example, we will build upon this in later articles to showcase the advanced capabilities offered by OneFuse as a platform.

Terraform with OneFuse: DNS

Before we begin there are prerequisites you will want to have ready.

Prerequisites

Creating the Terraform Configuration

To begin we will need to initialize the OneFuse Terraform provider.  To do this we will need the following statement:

Provider Declaration

terraform {
  required_providers {
    onefuse = {
      source  = "CloudBoltSoftware/onefuse"
      version = ">= 1.20.0"
   }
  }
  required_version = ">= 0.13"
}
provider "onefuse" {
  scheme     = "https"
  address    = "onefuse_fqdn"
  port       = "443"
  user       = "admin"
  password   = "admin"
  verify_ssl = "false"
}

The OneFuse Terraform provider is available in the Terraform Registry.  By point to the source “CloudBoltSoftware/onefuse”  Terraform will automatically download the OneFuse provider based on the required_version specified.  In the example above that will be v1.20.0 or higher.

Data Source

Next, we need to leverage the OneFuse provider Data Source to lookup the DNS policy we would like to use.  This will allow us to determine which policy we will be using by its name.

// OneFuse Data Source for DNS Policy to lookup policy ID
data "onefuse_dns_policy" "policy" {
  name = "default"
}

In the above example I am using the “data” source type “onefuse_dns_policy” to lookup the policy by the name “default” and store it as “policy”  We will then be able to refer to the results as data.onefuse_dns_policy.policy.

Resource

Next, we need to create a resource that will trigger Terraform to contact OneFuse to create the DNS record.  To do this, we will need the following declaration:

resource "onefuse_dns_record" "dns-record" {
    name = "test-dns"
    policy_id = data.onefuse_dns_policy.policy.id
    zones = ["infoblox851.sovlabs.net"]
    value = "10.30.29.240"
    template_properties = {}
}

Here, we are creating a resource that uses “onefuse_dns” with the name “dns-record”.  We need to tell the resource the id for the policy we want to use.  To do this we simple reference the data source we looked up.  To get the id we reference “data.onefuse_dns_policy.policy.id”  We also need to tell it the name and the IP address we want to use. 

In the article “Creating a OneFuse DNS Policy”, we created a DNS policy that contains all the relevant configuration needed.

Because the DNS policy does not have any user defined variables we do not need to pass anything in for the “template_properties”.

Putting it all together

Our completed plan will look like the following:

terraform {
  required_providers {
    onefuse = {
      source  = "CloudBoltSoftware/onefuse"
      version = ">= 1.20.0"
   }
  }
  required_version = ">= 0.13"
}

// Inititalize OneFuse Provider
provider "onefuse" {

  scheme     = "https"
  address    = "onefuse12bp.sovlabs.net"
  port       = "443"
  user       = "admin"
  password   = "admin"
  verify_ssl = "false"
}

// OneFuse Data Source for DNS Policy to lookup policy ID
data "onefuse_dns_policy" "policy" {
  name = "default"
}

// OneFuse Resource for DNS Record
resource "onefuse_dns_record" "dns-record" {
    
    name = "test-dns"
    policy_id = data.onefuse_dns_policy.policy.id
    zones = ["infoblox851.sovlabs.net"]
    value = "10.30.29.240"
    template_properties = {}
}

Applying the Configuration

  1. Init
    • terraform init
  2. Plan
    • terraform plan
  3. Apply
    • terraform apply
    • When you log in to the OneFuse UI, navigate to Modules > DNS and scroll down to Managed DNS Records. You will see your newly created DNS record in the list.
  4. Destroy
    • terraform destroy

Once destroyed, you will see the Managed DNS Record in OneFuse has been removed and the record no longer exists.

For example Terraform Configurations: visit our onefuse-examples in our GitHub repo.

Want to try OneFuse with Terraform for yourself? Check out the WWT HOL Accelerating Terraform with OneFuse.

Questions or comments? Visit our

Comments are closed.

Skip to toolbar