Total Pageviews

Configure vRealize Automation using Terraform


 You probably are aware of the VMware has a HashiCorp Terraform provider. which we can be used to configure our vRealize Automation (vRA) infrastructure as well requesting deployments. In this blog I am going to cover, how to configure cloud account for Vsphere .

 

In upcoming blog, I will cover how to configure below resource using Terraform .

 Cloud account for AWS,

Cloud account for Azure

Cloud account for google. 

Cloud Zone

Project

Images

Flavors

Create a vRA Cloud Account for Vsphere :-

I have created a  folder to hold my Terraform configuration files:

main.tf – this is my main terraform file in which I am describing the desired state of my environment

terraform.tfvars – used for setting variable values

variables.tf – used for declaring variables

Create a new file called “main.tf” and define the required providers block to be used, in this blog, we are not going to define any version but by defult going to use latest version. Following this, create a provider block called “vra” and Second block to be created as a data source and for this we will pull vSphere information for cloud account. The third block is a resource block, meaning that something will be created, in this case we have a resource  “vra_cloud_account_vsphere.



.  provider "vra" {
  url           = var.url
  refresh_token = var.refresh_token
  insecure      = var.insecure // false for vRA Cloud and true for vRA 8.0
}


data "vra_region_enumeration_vsphere" "vca01" {
  username                = var.username
  password                = var.password
  hostname                = var.hostname
  accept_self_signed_cert = true
}

resource "vra_cloud_account_vsphere" "this" {
  name        = "tf-vsphere-account"
  description = "foobar"
  username    = var.username
  password    = var.password
  hostname    = var.hostname
  
regions                      = data.vra_region_enumeration_vsphere.inprmvca01.regions
  accept_self_signed_cert      = true

  tags {
    key   = "Cloud"
    value = "Vsphere"
  }
}


The next file is “variable.tf” and  where the variables are defined. Each variable block is created with the variable name. below are the example. 


variable "refresh_token" {
}

variable "url" {
}

variable "insecure" {
}

variable "username" {
}

variable "password" {
}

variable "hostname" {
}

Generating an API token 

 Terraform to authenticate with the vRealize Automation API we need have API token – this can either be an access token or a refresh token. In my lab I have generated refresh_token. Access and Refresh tokens are based on your login credentials and expire in 8 hours or 6 months respectively but share the scope and permissions as your user account and cannot be revoked without disabling the account. For vRealize Automation 8 (on-premises) you will need to use the instructions or scripts provided to retrieve a refresh token.


In Final step need to define the values of each variable. Let’s create a “variables.tfvars” file and enter your environmental details in the file, as per the below example.

refresh_token = "7wq3LMUWCARyEbcGaQUj6hb14gv7w2XE"
url = "https://vra08.mylabs.com"
insecure =false
username = "randhirkumar.chaubey"
password = "XXXXXXXXXXXXXX"
hostname = "vca01. mylabs.com"

The provider vra definition references the two variables we’ve configured in the terraform.tfvars file through the “var” keyword. Now we can run terraform init to see if the provider configures successfully.


The provider is initialized and is ready to start configuring vRealize Automation! 

 

Now we can see at first glance what this will going to  create a new Cloud Account named “tf-vsphere-account”, using the variables declared in variables.tf.  Executing terraform plan will describe what will happen if we run the code: 


Once you run the “terraform plan” and confirm everything looks correct then after run “terraform apply” to create resource (Cloud account for Vsphere).  

 

When command has been finished successfully without error, then you will see new Cloud account for Vsphere in vRA with the properties configured as we set in the “Main.tf” file. 


I hope you enjoy reading this blog as much as I enjoyed writing it. Feel free to share this on social media if it is worth sharing.





3 comments:

Deploy Windows VMs for vRealize Automation Installation using vRealize Suite Lifecycle Manager 2.0

Deploy Windows VMs for vRealize Automation Installation using vRealize Suite Lifecycle Manager 2.0 In this post I am going to describe ...