WARNING.  This script is to be used for informational and learning purposes only.  Should you choose to modify and or include this script in your test or production environments, you do so at your own risk.  Custom scripts are only supported by Embotics, when they are produced by an Embotics Application Architect as part of a paid service engagement.

Should you require assistance modifying or troubleshooting the script, please contact your Customer Advocate who will provide you with a quote for Professional Services.

Terraform is a tool for creating and managing infrastructure using well defined configuration files to describe the infrastructure components which will be deployed. This integration allows you to deploy these template files using a Service Request in vCommander.


Requirements


Configure the Terraform Command, Decommission and Init Script file


  1. Extract the Terraform Integration zip into a Terraform folder in your vCommander Scripts folder. This article assumes this is located at C:\Scripts\Terraform\.
  2. Open the Terraform_Command_Script.ps1 file and locate the "User Configured Variables" section.
  3. In the User Configured Variables section, set the path to the vCommander Credentials file and the URL of the vCommander Server. Save and close the file.
  4. Repeat steps 2 and 3 for the Terraform_Init_Script.ps1 and the Terraform_Decommission_Script.ps1  file and save and close the file.


Create the Terraform Organization


The Terraform Service Request will need a form to allow you to identify the owner of the deployed resources. That form will need to be assigned to an Organization.

  1. Log into your vCommander Administrative portal. Select Configuration -> Organizations and Quotas from the top menu and then select the Organizations tab.
  2. Select the Add button. Set the Organization Name to "Terraform Org" and click Finish.
    If you need to configure additional Organization details click next instead of Finish and configure the Organization as required.


Create the Terraform Deployment Service Request Form


Now that the Organization has been created we need to create a Form to capture the User that will be set as the owner of the deployed VM created by the Terraform Template.

  1. Log into your vCommander Administrative portal. Select Configuration -> Service Request Configuration from the top menu and then select the Form Designer tab.
  2. Click Add under the Form Library section on the left hand side. Set the Form Name to "Terraform Deployment". Under the Organizations section choose the Terraform Org and Add it. Click Ok.
  3. If the Primary Owner field is not already present in the form designer section click the Primary Owner link on the right hand side to add it. 
  4. Click Edit on the Primary Owner element, clear the Display Only checkbox and check the Required checkbox. Click OK.
  5. Click Save to save the form.


Create the Deploy Terraform Template Completion Workflow


Next, before creating the Service Definition, we need to create the Completion Workflow to run the Terraform scripts.

  1. Log into your vCommander Administrative portal. Select Configuration -> Service Request Configuration from the top menu and then select the Completion Workflow tab.
  2. Click the Add button. Set the Name to "Deploy Terraform Template". Click Next.
  3. On the Steps page, click Add and select an Execute Script step type. Set the Step Name to "Initialize Terraform". Set the Command Line to:
    powershell.exe  -ExecutionPolicy Bypass  &{C:\scripts\terraform\Terraform_Init_Script.ps1}

  4. Click the Add button again. Select an Execute Script step type. Set the Step Name to "Deploy Terraform Template". Set the Command Line to:
    powershell.exe  -ExecutionPolicy Bypass  &{C:\scripts\terraform\Terraform_Command_Script.ps1  -PrimaryOwner #{request.primaryOwner.email}}

  5. Click Next. Select the "Do not apply this workflow to any custom component" option and click Next.
  6. On the Summary page, click Finish.


Create the Terraform Deployment Service Definition


Finally, we'll create the Service Definition for the Terraform deployment service.

  1. Log into your vCommander Administrative portal. Select Configuration -> Service Request Configuration from the top menu and then select the Service Catalog tab.
  2. Click the Add button. Set the Name to "Terraform Deployment Example". Click Next.
  3. On the Component Blueprints page, click Add and select a New Component Type. Set the Name to "Terraform Template" and set the Cost to $0. Click OK and then click Next.
  4. On the Terraform Template page select the "Deploy Terraform Template" workflow from the Completion Workflow dropdown. Click Next.
  5. On the Deployment page click Next. On the Visibility page select Publish - Global.  Click Next
  6. On the Summary page, click Finish.

In addition to deploying the infrastructure in the Terraform Template the script behind this workflow will attempt to assign the VM created by this service request to the Terraform Org and set the primary owner as the user who made the Service Request.


Now that the service request to deploy infrastructure is complete we will need to create a decommissioning Service Request to tear down the infrastructure that was deployed.


Create the Terraform Decommission Workflow


First, we need to create the Completion Workflow that will call our script.

  1. Log into your vCommander Administrative portal. Select Configuration -> Service Request Configuration from the top menu and then select the Completion Workflow tab.
  2. Click the Add button. Set the Name to "Decommission Terraform Template Workflow". Click Next.
  3. On the Steps page, click Add and select an Execute Script step type. Set the Step Name to "Decommission Template". Set the Command Line to:
    powershell.exe  -ExecutionPolicy Bypass  &{C:\scripts\terraform\Terraform_Decommission_Script.ps1}

  4. Click Next. Select the "Do not apply this workflow to any custom component" option and click Next.
  5. On the Summary page, click Finish.


Create the Terraform Decommission Service Definition


Now we'll create the Service Definition for the Terraform Decommission service.

  1. Log into your vCommander Administrative portal. Select Configuration -> Service Request Configuration from the top menu and then select the Service Catalog tab.
  2. Click the Add button. Set the Name to "Terraform Decommissioning Example". Click Next.
  3. On the Component Blueprints page, click Add and select a New Component Type. Set the Name to "Decommission Terraform Template" and set the Cost to $0. Click OK and then click Next.
  4. On the Terraform Template page select the "Decommission Terraform Template Workflow" workflow from the Completion Workflow dropdown. Click Next.
  5. On the Deployment page click Next. On the Visibility page select Publish - Specific Organizations, Users and Groups. Select the Terraform Org from the Organizations dropdown and click Add. Click Next
  6. On the Summary page, click Finish.

This Decommissioning service request will automatically tear down any infrastructure that was created using the Deploy Terraform service request we created earlier. This happens automatically and doesn't require additional user input.