Skip to content

Commit

Permalink
Add deployment resource and data sources for catalog_item and deploym…
Browse files Browse the repository at this point in the history
…ent (#91)

Signed-off-by: Deepak Mettem <[email protected]>
  • Loading branch information
dmettem authored and markpeek committed Oct 31, 2019
1 parent f7bf13c commit 422300d
Show file tree
Hide file tree
Showing 29 changed files with 1,752 additions and 1 deletion.
11 changes: 11 additions & 0 deletions examples/deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# deployment examples

This directory covers examples on how to create a deployment in different ways.

## Getting Started

Follow these examples for creating deployments:

* [Deployment](blueprint/README.md) with a blueprint id
* [Deployment](catalog_item/README.md) with a catalog item id
* [Deployment](no_resources/README.md) with no resources
26 changes: 26 additions & 0 deletions examples/deployment/blueprint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# deployment with a blueprint id example

This is an example on how to crete a deployment in vRealize Automation(vRA) using an existing blueprint.

## Getting Started

There are variables which need to be added to terraform.tfvars.

* `url` - The URL for the vRealize Automation (vRA) endpoint
* `refresh_token` - The refresh token for the vRA account
* `project_name` - Project Name
* `blueprint_id` - Blueprint ID
* `blueprint_version` - Blueprint Version
* `deployment_name` - Deployment Name

To facilitate adding these variables, a sample tfvars file can be copied first:
```shell
cp terraform.tfvars.sample terraform.tfvars
```

Once the information is added to `terraform.tfvars`, the cloud account can be brought up via:

```shell
terraform init
terraform apply
```
25 changes: 25 additions & 0 deletions examples/deployment/blueprint/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
provider "vra" {
url = var.url
refresh_token = var.refresh_token
}

data "vra_project" "this" {
name = var.project_name
}

resource "vra_deployment" "this" {
name = var.deployment_name
description = "terraform test deployment"

blueprint_id = var.blueprint_id
blueprint_version = var.blueprint_version
project_id = data.vra_project.this.id

inputs = {
flavor = "small"
image = "centos"
}

expand_resources = true
expand_last_request = true
}
6 changes: 6 additions & 0 deletions examples/deployment/blueprint/terraform.tfvars.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
refresh_token = ""
url = ""
project_name = ""
blueprint_id = ""
blueprint_version = ""
deployment_name = ""
17 changes: 17 additions & 0 deletions examples/deployment/blueprint/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "url" {
}

variable "refresh_token" {
}

variable "project_name" {
}

variable "blueprint_id" {
}

variable "blueprint_version" {
}

variable "deployment_name" {
}
4 changes: 4 additions & 0 deletions examples/deployment/blueprint/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
26 changes: 26 additions & 0 deletions examples/deployment/catalog_item/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# deployment with a catalog item example

This is an example on how to request/create a deployment in vRealize Automation(vRA) using an existing catalog item.

## Getting Started

There are variables which need to be added to terraform.tfvars.

* `url` - The URL for the vRealize Automation (vRA) endpoint
* `refresh_token` - The refresh token for the vRA account
* `project_name` - Project Name
* `catalog_item_name` - Catalog Item Name
* `catalog_item_version` - Catalog Item Version
* `deployment_name` - Deployment Name

To facilitate adding these variables, a sample tfvars file can be copied first:
```shell
cp terraform.tfvars.sample terraform.tfvars
```

Once the information is added to `terraform.tfvars`, the cloud account can be brought up via:

```shell
terraform init
terraform apply
```
31 changes: 31 additions & 0 deletions examples/deployment/catalog_item/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
provider "vra" {
url = var.url
refresh_token = var.refresh_token
insecure = var.insecure
}

data "vra_project" "this" {
name = var.project_name
}

data "vra_catalog_item" "this" {
name = var.catalog_item_name
expand_versions = true
}

resource "vra_deployment" "this" {
name = var.deployment_name
description = "terraform test deployment"

catalog_item_id = data.vra_catalog_item.this.id
catalog_item_version = var.catalog_item_version
project_id = data.vra_project.this.id

inputs = {
flavor = "small"
image = "centos"
}

expand_resources = true
expand_last_request = true
}
7 changes: 7 additions & 0 deletions examples/deployment/catalog_item/terraform.tfvars.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
refresh_token = ""
url = ""
insecure = ""
project_name = ""
catalog_item_name = ""
catalog_item_version = ""
deployment_name = ""
20 changes: 20 additions & 0 deletions examples/deployment/catalog_item/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "url" {
}

variable "refresh_token" {
}

variable "insecure" {
}

variable "project_name" {
}

variable "catalog_item_name" {
}

variable "catalog_item_version" {
}

variable "deployment_name" {
}
4 changes: 4 additions & 0 deletions examples/deployment/catalog_item/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
24 changes: 24 additions & 0 deletions examples/deployment/no_resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# deployment with no resources example

This is an example on how to crete a deployment in vRealize Automation(vRA) without any resources.

## Getting Started

There are variables which need to be added to terraform.tfvars.

* `url` - The URL for the vRealize Automation (vRA) endpoint
* `refresh_token` - The refresh token for the vRA account
* `project_name` - Project Name
* `deployment_name` - Deployment Name

To facilitate adding these variables, a sample tfvars file can be copied first:
```shell
cp terraform.tfvars.sample terraform.tfvars
```

Once the information is added to `terraform.tfvars`, the cloud account can be brought up via:

```shell
terraform init
terraform apply
```
16 changes: 16 additions & 0 deletions examples/deployment/no_resources/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
provider "vra" {
url = var.url
refresh_token = var.refresh_token
insecure = var.insecure
}

data "vra_project" "this" {
name = var.project_name
}

resource "vra_deployment" "this" {
name = var.deployment_name
description = "terraform test deployment"

project_id = data.vra_project.this.id
}
5 changes: 5 additions & 0 deletions examples/deployment/no_resources/terraform.tfvars.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
refresh_token = ""
url = ""
insecure = ""
project_name = ""
deployment_name = ""
14 changes: 14 additions & 0 deletions examples/deployment/no_resources/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "url" {
}

variable "refresh_token" {
}

variable "insecure" {
}

variable "project_name" {
}

variable "deployment_name" {
}
4 changes: 4 additions & 0 deletions examples/deployment/no_resources/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
49 changes: 49 additions & 0 deletions vra/catalog_item_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package vra

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/vmware/vra-sdk-go/pkg/models"
)

// resourceReferenceSchema returns the schema to use for the catalog item type property
func catalogItemVersionSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"created_at": {
Type: schema.TypeString,
Optional: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"id": {
Type: schema.TypeString,
Optional: true,
},
},
},
}
}

func flattenCatalogItemVersions(catalogItemVersions []*models.CatalogItemVersion) []map[string]interface{} {
if len(catalogItemVersions) == 0 {
return make([]map[string]interface{}, 0)
}

versions := make([]map[string]interface{}, 0, len(catalogItemVersions))

for _, version := range catalogItemVersions {
helper := make(map[string]interface{})
helper["created_at"] = version.CreatedAt.String()
helper["description"] = version.Description
helper["id"] = version.ID

versions = append(versions, helper)
}

return versions
}
Loading

0 comments on commit 422300d

Please sign in to comment.