I wanted to write about Terraform, the Orchestration tool that I enjoy using in my own environment. I actually have a lot to write, but I want to solve a lot of problems about Terraform with this article. First, let’s add a Custom Provider to Terraform. Which is vRealize Automation Cloud Plugin, one of VMware’s latest technologies, so that we can solve the complex installation of this new technology.
I hope what I tell you will be useful.
So let’s start 🙂
Terraform is an Orchestration tool designed for “Infrastructure as Code” structure that helps you manage your cloud services by writing code. The best thing Terraform has provided us is that it provides immutability and multi-vendor. If you or your customer receives cloud service from more than one vendor, you can manage the environment with Terraform by writing code from a single screen and you do not need to work separately with each vendor’s console or management tools. To summarize, with Terraform you write the code that creates the infrastructure, you see your executing plans, and your infrastructure is created(After your approval).
Now let’s get started with Terraform installation.Terraform.io has a nice video for installation.
You can easily install the Terraform after you watch this video and you will now have terraform installed in your environment. If you have a problem with this part, you can write to me.
In order to add VRA as a custom provider to Terraform, the GO installation that we will do here is very important because we will run the project from github with GO language. A configuration error here will cause problems when running the current project. We start the Ubuntu environment with the standard Go installation.
I suggest you update your system first. To avoid any version problems.
$ sudo apt-get update
$ sudo apt-get -y upgrade
Download the Go language binary archive file using following link.
$ wget https://dl.google.com/go/go1.13.3.linux-amd64.tar.gz
Then extract the downloaded archive and install it to the desired location on the system. I am installing it under /usr/local directory. You can also put this under the home directory or other location.
$ sudo tar -xvf go1.13.3.linux-amd64.tar.gz
$ sudo mv go /usr/local
Now this part is very important, Setup a GOLang project structure as follows:
GOROOT and GOPATH paths are the most common errors when making this installation. We need to know what to write for GOROOT and GOPATH.
We will write them into ~ / .profile.
~/.profile: .profile file in Linux comes under the System startup files(defines user environment after reading the initialization files that you have set up when you log in to shell). So .profile is a user specific shell initialization script/file.
$ vim ~/.profile
Add to bottom line:
GOROOT is a golang library path.
GOPATH is a path pointing toward the source code directory.
Export GOPATH=/home/ubuntu/TerraformPluginProject (*ubuntu is my own user)
Now set the PATH variable to access go binary system wide.
Save and close !
Do not forget source command for .profile change:
$ source ~/.profile
GO is okey 😊
Set terraform provider
Create ~/.terraformrc and put following content in it.
Write into ~/.terraformrc
~ / .terraformrc recognizes the provider extension by the name vra.
Save and Close !
This part is very important. If you are in the wrong path for ‘go get’ command, command is not run. You have to go ‘/usr/local/go/src’ path with cd command. So first of all,
$ cd /usr/local/go/src
Clone repo code into go project using go get
$ go get github.com/vmware/terraform-provider-vra
Navigate to$HOME/TerraformPluginProject/src/github.com/vmware/terraform-provider-vra and run go build command to generate plugin binary.
$ cd $HOME/TerraformPluginProject/src/github.com/vmware/terraform-provider-vra
$ go build -o /home/ubuntu/TerraformPluginProject/bin/terraform-provider-vra
And finish 😊
Now your Terraform tool in your environment recognizes VRA. You are also ready to work in your VRA Cloud environment. In another article I will write about what we can do with examples.
Any problems can also contact me. I hope it was useful.