Why would I want to use Terraform via SSH in vRealize Automation and how I end up doing so, that’s what you will find out in this article.
When you start looking at how to implement Terraform in vRealize Automation you will soon end up looking at this page. Well that is not how I would like to implement Terraform within vRealize Automation. I would like to setup my own terraform server (linux + terraform CLI) and use that instead. Since Terraform CLI is basically sending some SSH commands to a linux server that shouldn’t be that hard.
Setting up the Linux Server
- Install Terraform (link)
- Create folder structure
- /opt/terraform/github
In here I’ll setup a Git Repository containing the Terraform Projects - /opt/terraform/providers
In here I’ll place the providers
- /opt/terraform/github
- Create user account:
[elementor-template id=”475″] - Create a group:
[elementor-template id=”478″] - Put user in group:
[elementor-template id=”481″] - Set user and group as owner of the previous folders:
[elementor-template id=”484″] - Allow user to connect via SSH
- Edit the config file via:
[elementor-template id=”487″] - In the end of the file add the following:
[elementor-template id=”490″]
- Edit the config file via:
- To make use of the offline providers you must make some changes under the user account (read also here and here):
- Log in as user vratf
- Create and edit a custom config file in the home directory:
[elementor-template id=”493″] - Add the following inside:
[elementor-template id=”502″] - Edit the users profile (.bashrc)
[elementor-template id=”496″] - Add below to create an environmental variable:
[elementor-template id=”505″]
For now I use the command “terraform providers mirror” to get the offline files in the right format. Which I then copy to the /opt/terraform/providers folder.
Well that was most that there is about to say about setting up the Linux Server with Terraform (I’m not going to point out how to setup the Github Repository, that outside the scope of this article).
How to use Terraform via SSH?
I have looked at some possibilities to use it:
- SSH Host
- vRO SSH Script Host workflow
- Powershell
SSH Host
When I tried to use this plugin I had an issue with the password. That will be “VCOencrypted” which makes connecting to the server a bit complicated. I was hoping it was more like the Powershell host, but this plugin doesn’t have “connect” or “opensession” functions. When looking into the encryption I have found some articles (1, 2 and 3), but I stopped further exploring this option at this point.
vRO SSH Script Host workflow
This is based on this article. You’ll end up with a workflow which uses a Configuration Element in which the host details (username, password, port number, server name, …) are available.
It works like a charm! Just run the workflow, specify the command to run and it will execute the command and return the output.
Powershell
Since I work a lot with Powershell, I would like to use the powershell host, which is also setup with an internal Git repository.
To use Terraform via SSH I wrote the following PowerShell function:
[elementor-template id=”499″]
tfFolder will be the project which is used
tfCommand will be the command to execute (terraform init, plan, …)
tfEnvironment will be used to determine in which DTAP environment we need to run the command.
I recently started using the secretmanagement and secretstore modules for handling secrets on the Powershell host. I’ll soon write an article about that, I really enjoy using these modules. Because of a naming format, I can easily use the environment to get the appropriate inputs:
- SSHUsername
- SSHPassword
- SSHBaseFolder (/opt/terraform/github/)
Conclusion
I’ll continue developing a vRO workflow to create some infra using the Terraform NSXT provider using the Powershell function.

What specific password issue did the author encounter when attempting to use the plugin mentioned in the article? Visit us Telkom University