OneFuse SPS Groups in Terraform

Overview

In this article we will go over how to use OneFuse Static Property Set (SPS) groups in Terraform. We will be using 2 Static Property Sets (SPS) to drive the naming policy we have.
 

Considerations

We will also assume that you have OneFuse and Terraform configured

OneFuse Configuration/Validation

Validate Naming Sequence and Naming Policy

  1. Log into OneFuse and go to the Naming section under Modules

    1. In our example Naming Policy below, you can see some templated {{}} values in the Naming Template section. These will be explained when we get to the Static Property Sets (SPS)

    2. We kept the Naming Sequence very generic for this test (Maximum Length is 3, Padding Character is 0, etc). You can also see the same template values in the Unique Key section (minus the sequence) which will be explained in the next section.

      This was just an overview of the Naming Policy and Naming Sequence. More information can be found in the Additional Information section at the bottom.

       

  2. Now that we’ve verified that our Naming Policy/Sequence looks good, we can move to the Static Property Sets (SPS).

Validate Static Property Sets (SPS)

  1. Log into OneFuse and go to the Static Property Sets section under Templating

  2. Locate the Static Property Set(s) that you’re going to be using and view/edit it

    1. In the example(s) below, we’re using Static Property Set (SPS) called Windows and Production. In the Static Property Set section is where we’re going to be passing in the values for those properties that we templated in the Naming Policy/Sequence.

      Windows SPS Group


      Production SPS Group

      More information can be found in the Additional Information section at the bottom.

Terraform Configuration/Validation

TF File Verification/Modification

  1. Open up your Terraform files in the text editor of your choice and verify that you have the correct settings. If any settings need to be changed, feel free to do so at this time (You can use my examples below for reference)

  2. We’re populating the data and resource objects for Naming and Static Property Sets in the main.tf file.

    terraform {
      required_providers {
        onefuse = {
          source  = "CloudBoltSoftware/onefuse"
          version = ">= 1.10.1"
        }
      }
      required_version = ">= 0.13"
    }
    
    // Comment out above for Terraform 0.12
    
    
    // Inititalize OneFuse Provider
    provider "onefuse" {
      scheme     = var.onefuse_scheme
      address    = var.onefuse_address
      port       = var.onefuse_port
      user       = var.onefuse_user
      password   = var.onefuse_password
      verify_ssl = var.onefuse_verify_ssl
    }
    
    // OneFuse Static Property Set
    data "onefuse_static_property_set" "windows" {
      name = "Windows"
    }
    
    data "onefuse_static_property_set" "production" {
      name = "Production"
    }
    
    // Naming Policy data source
    data "onefuse_naming_policy" "machine" {
      name = "demoPolicy"
    }
    
    resource "onefuse_naming" "machine-name" {
      naming_policy_id        = data.onefuse_naming_policy.machine.id // Refers to onefuse_naming_policy data source to retrieve ID
      dns_suffix              = ""
      template_properties = {
        os                = data.onefuse_static_property_set.windows.properties.os
        type              = data.onefuse_static_property_set.windows.properties.type
        env               = data.onefuse_static_property_set.production.properties.env
        loc               = data.onefuse_static_property_set.production.properties.loc
      }
    }
    
    // Outputs
    output "name" {
      value = onefuse_naming.machine-name.name
    }
    
    output "dns_suffix" {
      value = onefuse_naming.machine-name.dns_suffix // Refers to dns_sudffix output by naming is defined in policy
    }


3. Once we have verified everything, we can continue on to the next step of building the server with Terraform

Generating Name with Terraform

  1. Open your console window (we will be using Visual Studio Code in this example) and go to the directory of your TF files

  2. Once you’re there, we will run terraform init

    1. Terraform init will initialize all of the providers and you can see in the below screenshot that OneFuse 1.2 and Nutanix 1.2.0 were initialized.

  3. If you see a message that says Terraform has been successfully initialized!, then we’re good to continue to the next step.

  4. Now that everything is initialized, we’ll run terraform plan to make sure everything looks good with the build before we do the apply

    1. The terraform plan output is very long so it was not included here

  5. Take a look through the output from the terraform plan and make sure that everything looks correct

  6. If all looks good with the terraform plan, we’ll do a terraform apply now to build the server

  7. If the terraform apply completed successfully, you should see a message saying “Apply Complete!

OneFuse Validation

  1. Log back into OneFuse and go to the Naming section under Modules. Scroll down to the bottom and look for the Managed Names section. Verify that the Managed Object (MO) exists for your new server

    1. We can see that the correct name is listed below and that it used the correct Naming Policy that we passed in. It pulled all of the correct values from both Static Property Sets so this test was successful



Additional information

OneFuse - Terraform Provider

OneFuse - Naming

OneFuse - Static Property Sets

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.