vmware-archive / legacy-terraform-provider-vra7

Terraform provider for vRealize Automation 7
Mozilla Public License 2.0
60 stars 35 forks source link

This project has moved to the terraform-providers organization and is archived.

The new location is here: https://github.com/terraform-providers/terraform-provider-vra7

VMware Terraform provider for vRealize Automation 7

Build Status

A self-contained deployable integration between Terraform and vRealize Automation (vRA) which allows Terraform users to request/provision entitled vRA catalog items using Terraform. Supports Terraform destroying vRA provisioned resources.

Getting Started

These instructions will get you a copy of the project up and run on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

To get the vRA plugin up and running you need the following things.

Project Setup

Setup a GOLang project structure as follows:

|-/home/<USER>/TerraformPluginProject/
    |-bin/
    |-pkg/
    |-src/

Environment Setup

Set following environment variables.

Linux Users

GOROOT is a golang library path.

export GOROOT=/usr/local/go

GOPATH is a path pointing toward the source code directory.

export GOPATH=/home/<user>/TerraformPluginProject

Windows Users

GOROOT is a golang library path

set GOROOT=C:\Go

GOPATH is a path pointing toward the source code directory.

set GOPATH=C:\TerraformPluginProject

Set terraform provider

Linux Users

Create ~/.terraformrc and put following content in it.

    providers {
         vra7 = "/home/<USER>/TerraformPluginProject/bin/terraform-provider-vra7"
    }

Windows Users

Create %APPDATA%/terraform.rc and put following content in it.

    providers {
         vra7 = "C:\\TerraformPluginProject\\bin\\terraform-provider-vra7.exe"
    }

Installation

Clone repo code into go project using go get

    go get github.com/vmware/terraform-provider-vra7

Create Binary

Linux and MacOS Users

Navigate to /home/<USER>/TerraformPluginProject/src/github.com/vmware/terraform-provider-vra7 and run go build command to generate plugin binary.

    go build -o /home/<USER>/TerraformPluginProject/bin/terraform-provider-vra7

Windows Users

Navigate to C:\TerraformPluginProject\src\github.com\vmware\terraform-provider-vra7 and run go build command to generate plugin binary.

    go build -o C:\TerraformPluginProject\bin\terraform-provider-vra7.exe

Usage

Configure

The VMware vRA terraform configuration file contains two objects.

Provider

This part contains service provider details.

Provider block contains four mandatory fields:

Example:

    provider "vra7" {
      username = "vRAUser1@vsphere.local"
      password = "password123!"
      tenant = "corp.local.tenant"
      host = "http://myvra.example.com/"
      insecure = false
    }

Resource

This part contains any resource that can be deployed on that service provider. For example, in our case machine blueprint, software blueprint, complex blueprint, network, etc.

Syntax:

resource "vra7_deployment" "<resource_name1>" {
}

The resource block contains mandatory and optional fields.

Mandatory:

One of catalog_item_name or catalog_item_id must be specified in the resource configuration.

Optional:

Example 1:

resource "vra7_deployment" "example_machine1" {
  catalog_item_name = "CentOS 6.3"
  reasons      = "I have some"
  description  = "deployment via terraform"
   resource_configuration = {
         Linux.cpu = "1"
         Windows2008R2SP1.cpu =  "2"
         Windows2012.cpu =  "4"
         Windows2016.cpu =  "2"
     }
     deployment_configuration = {
         _leaseDays = "5"
     }
     count = 3
}

Example 2:

resource "vra7_deployment" "example_machine2" {
  catalog_item_id = "e5dd4fba7f96239286be45ed"
   resource_configuration = {
         Linux.cpu = "1"
         Windows2008.cpu =  "2"
         Windows2012.cpu =  "4"
         Windows2016.cpu =  "2"
     }
     count = 4
}

Save this configuration in main.tf in a path where the binary is placed.

Execution

These are the Terraform commands that can be used for the vRA plugin:

Navigate to the location where main.tf and binary are placed and use the above commands as needed.

Scripts

update_resource_state.sh

There are few changes in the way the terraform config file is written.

  1. The resource name is renamed to vra7_deployment from vra7_resource.
  2. catalog_name is renamed to catalog_item_name and catalog_id is renamed to catalog_item_id.
  3. General properties of deployment like description and reasons are to be specified at the resource level map instead of deployment_configuration.
  4. catalog_configuration map is removed.
  5. Custom/optional properties of deployment are to be specified in deployment_configuration instead of catalog_configuration.

These changes in the config file will lead to inconsistency in the terraform.tfstate file of the existing resources provisioned using terraform. The existing state files can be converted to the new format using the script, update_resource_state.sh under the scripts folder.

Note: This script will only convert the state file. The changes to the config file(.tf file) still needs to be done manually.

How to use the script

  1. Copy the script, script/update_resource_state.sh in the same directory as your terraform.tfstate file.
  2. Change the permission of the script, for example chmod 0700 update_resource_state.sh.
  3. Run the script, ./update_resource_state.sh.
  4. The terraform.tfstate will be updated to the new format and a back-up of the old file is saved as terraform.tfstate_back

Contributing

The terraform-provider-vra7 project team welcomes contributions from the community. Before you start working with terraform-provider-vra7, please read our Developer Certificate of Origin. All contributions to this repository must be signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on as an open-source patch. For more detailed information, refer to CONTRIBUTING.md.

License

terraform-provider-vra7 is available under the Mozilla Public License, version 2.0 license.