Setup vRealize Automation using Terraform

Reading Time: 3 minutes

VMware has created a HashiCorp Terraform provider which can be used to set up your vRealize Automation (vRA) infrastructure, along with requesting deployments and consuming XaaS resources. This post will cover the basics of setting up vRA using Terraform.

The first two posts in this series cover the basics of Infrastructure as Code with vRA and Terraform along with creating your first Terraform configuration to deploy a vSphere virtual machine. To get started, have a read of the documentation available for either vRA 8 or vRA 7.

This post will assume that vRA 8 has been deployed using vRealize Suite Lifecycle Manager, the vIDM has been configured for the required external accounts and a Cloud Account and Cloud Zone have been created to reference a vSphere environment. The below will presume the default user account, in this case, “configadmin” has also been created and that the Terraform version is 0.14.11 which can be downloaded from here.

Create a vRA Project

Create a new file called “main.tf” and define the required_providers block to be used, in this case, “vra” and define the source and version. Following this, create a provider block called “vra” and reference the variables which we’ll create next.

The next file is called “variable.tf” and it is where the variables are defined. Each variable block is created with the variable name, and it’s best practice to define a description, type and default value.

Create a new file called “projects.tf” and the first block to be created is a data source and for this we will retrieve the vRA Cloud Zone for the vSphere Cloud Zone which should already be created. The second block is a resource block, meaning that something will be created, in this case, a “vra_project”. Provide a name and description as a variable, along with your configuration to assign your existing vRA Cloud Zone to your new project. The first field is the zone_id retrieved from the previously defined data source, followed by the priority, max number of instances, cpu limit, memory limit and storage limit. The next few lines are optional, and set if resources should be shared from this project to other projects, any administrators and members that need to be added, an operational timeout set at the project level in case of long running operations, and the machine naming template.

With the “projects.tf” file now created, updated the “variables.tf” file with the new variables just used, to look like the below.

The final step is to define the values of each variable. To do this, create a “variables.tfvars” file and enter your environmental details in the file, as per the example below. Remember, all *.tfvars files should not be stored in source control such as git, as the values will differ between environments.

With all the files now created, run a “terraform plan” and confirm everything looks correct and that your new resource will be created, and then run “terraform apply”.

Once the apply command has finished, in vRA you will see the new project created with the properties configured exactly as set in the “projects.tf” file.

Whilst this post only covers the creating of a vRA project, you can use this same process to configure most of vRA, with documentation available on the vRA Terraform provider here.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.