Catalog Item Request with Terraform

Introduction

Hey guys. Recently I’ve been diving into IaC with Terraform quite a bit, and how we can use the Terraform vRA provider to interact with Aria Automation. In doing so I realised there is a gap in the market, I couldn’t find a decent blog article describing how to request a Service Broker catalog item with Terraform – so here it is.

Some Assumptions

So I’m assuming you are good with creating a Cloud Template in Assembler, versioning and releasing it to the Catalog so lets skip those steps as Aria Automation design is not the main focus of this article. You should have something like this ready to go – in my case a simple CentOS Catalog Item with the base input parameters of Project and Deployment Name.

Setting up Terraform

So now let’s get Terraform ready. Create yourself a new workspace in VS Code, basically a folder. From here you’ll first want to set up your terraform block and the vRA provider. I like to keep them in seperate files – terraform.tf and providers.tf. So at the time of writing the latest vRA provider version is 0.15.0.

terraform.tf

##################################################################################
# TERRAFORM BLOCK
##################################################################################

terraform {
  required_version = ">1.13"
  required_providers {
    vra = {
      source  = "vmware/vra"
      version = ">= 0.15.0"
    }
  }
}

providers.tf

provider "vra" {
  url           = var.url
  refresh_token = var.refreshToken
  insecure      = true
}

You’ll also want to get some data using data sources, so I’ve put these both into a data.tf file. You could just hard code the Project ID and Catalog Item ID in your Terraform configuration, but this way you can get this information dynamically from vRA.

  • Get the project you want to request against, as you’ll need the project id
  • Get the catalog item, as you’ll need the catalog item id parameter to submit a request

The Deployment Resource

data.tf

data "vra_catalog_item" "centos7-ct" {
  name            = var.catalog_item_name
  expand_versions = true
}

data "vra_project" "dev_project01" {
  name = var.project_name
}

The key resource here is the vra_deployment resource. It’s a little unintuitive as you’ve probably been searching for the catalog item resource instead. So this is pretty easy to use, there are only a few mandatory parameters in our simple Catalog Item case which doesn’t have any other inputs defined in the template canvas.

  • name -> Your deployment name, you can go ahead and hard code this for a quick test, but best to reference variables.tf file
  • description -> This is a description of your deployement, you can reference your variables.tf file
  • catalog_item_id -> The ID of the catalog item you are requesting. We are getting this from our data source
  • catalog_item_version -> The version of the catalog item to request, you can reference your variables.tf file
  • project_id -> the ID of the Project to submit the request to. We are getting this from our project data source

As you can see in the example comment block, you can specify other inputs depending on what you’ve exposed in your Assembler template.

deployments.tf

So as I’ve eluded to, for this Terraform workspace to work, you’ll need to create a variables.tf file containing your variable block definitions. I’ll leave that to you to figure out as there is plenty of decent information out there on setting up configuration parameters.

For this request test, I’ve stored my Aria Automation URL and API Token (refresh token) in terraform.tfvars file so they don’t need to be specified as inputs, but please DO NOT store your API token or any other sensitive information in this way outside of a home lab, as it will get pushed to GitHub or other repo along with the configuration files.

terraform.tfvars

url                  = "https://vra8app01.greghomelab.com"
refreshToken         = "xXxxxXxxxXxxxXxxxXxxxXxxxXxxxXxx"
catalog_item_version = "4"

Requesting a new Deployment

So if you’ve got this all setup well so far, go ahead and get ready to apply your Terraform configuration:

  • terraform fmt -> make sure your formatting is good
  • terraform validate -> validate / fix any configuration errors
  • terraform plan -out vra_request.tfplan -> create your execution plan and save to file
  • terraform apply vra_request.tfplan -> apply the configuration using the planned changes

If all goes well you’ll get your request submitted in Service Broker, and a new deployment with the name you specified in your variable block.

Summary

So we’ve seen how to use Terraform IaC to request vRA IaC Cloud Templates! A pretty powerful combination which takes advantage of the declarative nature of Terraform whilst using Aria Automation and Orchestrator to execute the more complex provisioning integrations for your virtual machines. Till next time, stay safe.

Leave a Reply