Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Re-designed the resource_configuration schema and fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Prativa20 committed Apr 6, 2020
1 parent 9c401d0 commit 113ee5c
Show file tree
Hide file tree
Showing 22 changed files with 1,389 additions and 961 deletions.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
## 0.5.1 (Unreleased)
## 1.0.0 (Unreleased)
FEATURES:

* The resource schema is modified to have more attributes for the vra7_deployment resource
* Feature request: Day 2: Change the number of VMs created by the vRA blueprint ([#47](https://github.com/terraform-providers/terraform-provider-vra7/issues/47))
* Does 'import' work? ([#29](https://github.com/terraform-providers/terraform-provider-vra7/issues/29))
* Need to import existing VMs ([#43](https://github.com/terraform-providers/terraform-provider-vra7/issues/43))
* Support Deployment Day 2 Change Lease action ([#54](https://github.com/terraform-providers/terraform-provider-vra7/issues/54))
* Create a data source for vra7_deployment resource ([#55](https://github.com/terraform-providers/terraform-provider-vra7/issues/55))

IMPROVEMENTS:

* Cleanup README
* Show all the data in the state file that is returned from a deployment resource GET ([#41](https://github.com/terraform-providers/terraform-provider-vra7/issues/41))
* Cannot pass array of values in element of deployment_configuration or resource_configuration ([#45](https://github.com/terraform-providers/terraform-provider-vra7/issues/45))
* `ip_address` can be accessed from the resource_configuration schema as a first class attribute

BUG FIXES:
* Terraform gets only first VM with _number_of_instances or _cluster > 1 ([#39](https://github.com/terraform-providers/terraform-provider-vra7/issues/39))
* Terraform refresh does not work as intended ([#38](https://github.com/terraform-providers/terraform-provider-vra7/issues/38))
* VRA Provider deletes resources from state file before receiving any "SUCCESSFUL" status response from VRA during terraform destroy ([#33](https://github.com/terraform-providers/terraform-provider-vra7/issues/33))
* Terraform apply returns empty ip address ([#27](https://github.com/terraform-providers/terraform-provider-vra7/issues/27))
* IPAddress return is empty with latest release of vRealize Automation ([#16](https://github.com/terraform-providers/terraform-provider-vra7/issues/16))
* Terraform adds resource in state file even though the request_status is "FAILED" ([#37](https://github.com/terraform-providers/terraform-provider-vra7/issues/37))


## 0.5.0 (November 06, 2019)
FEATURES:

Expand Down
181 changes: 13 additions & 168 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,151 +24,7 @@ Using the provider

See the [vra7 documentation](https://www.terraform.io/docs/providers/vra7/index.html) to get started using the vRealize Automation 7 provider.

Upgrading the provider
----------------------

The vra7 provider doesn't upgrade automatically once you've started using it. After a new release you can run

```bash
terraform init -upgrade
```

to upgrade to the latest stable version of the vra7 provider. See the [Terraform website](https://www.terraform.io/docs/configuration/providers.html#provider-versions)
for more information on provider upgrades, and how to set version constraints on your provider.

## Configure
The VMware vRA terraform configuration file contains two objects.

### Provider
This part contains service provider details.

Provider block contains four mandatory fields:
* `username` - vRA portal username
* `password` - vRA portal password
* `tenant` - vRA portal tenant
* `host` - End point of REST API
* `insecure` - In case of self-signed certificates, default value is false

**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.
* `catalog_item_name` - catalog_item_name is a field which contains valid catalog item name from your vRA
* `catalog_item_id` - catalog_item_id is a field which contains a valid catalog item id from your vRA

**Optional:**
* `description` - This is an optional field. You can specify a description for your deployment.
* `reasons` - This is an optional field. You can specify the reasons for this deployment.
* `businessgroup_id` - This is an optional field. You can specify a different Business Group ID from what provided by default in the template request, provided that your account is allowed to do it.
* `businessgroup_name` - This is an optional field. You can specify a different Business Group name from what provided by default in the template request, provided that your account is allowed to do it.
* `count` - This field is used to create replicas of resources. If count is not provided then it will be considered as 1 by default.
* `deployment_configuration` - This is an optional field. It can be used to specify deployment level properties like _leaseDays, _number_of_instances or any custom properties of the deployment. Key is any field name of catalog item and value is any valid user input to the respective field..
* `resource_configuration` - This is an optional field. If blueprint properties have default values or no mandatory property value is required then you can skip this field from terraform configuration file. This field contains user inputs to catalog services. Value of this field is in key value pair. Key is service.field_name and value is any valid user input to the respective field.
* `wait_timeout` - This is an optional field with a default value of 15. It defines the time to wait (in minutes) for a resource operation to complete successfully.


**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.

### Deployment Destroy
In case you are encountering the following error in vRA7:
```
Insufficient entitlement to destroy VM
```
Please set `deployment_destroy = true` which will cause the provider to destroy the deployment resource instead.

### Nested structures

At the moment Terraform SDK does not support nested dynamic types, which are used by vRA API.
Issue tracking development of this feature is on GitHub (Support the pseudo dynamic type)[https://github.com/hashicorp/terraform-plugin-sdk/issues/248].

In vRA Terraform Resource you can do it by passing JSON string, but only inside `deployment_configuration` for time being. You can use `jsonencode` Terraform function or multiline strings.
It's based on workaround used by other providers such as AWS and (IAM Policy resource)[https://www.terraform.io/docs/providers/aws/r/iam_policy.html#example-usage].

**Example 1:**
```hcl
resource "vra7_deployment" "example_machine1" {
catalog_item_name = "vNet"
deployment_configuration = {
"networkName" = "test VNET"
"businessGroups" = jsonencode("[\"bgTest1\", \"bgTest2\"]")
}
}
```

**Example 2:**
```hcl
resource "vra7_deployment" "example_machine1" {
catalog_item_name = "vNet"
deployment_configuration = {
"networkName" = "test VNET"
"businessGroups" = <<EOF
[
"bgTest1",
"bgTest2"
]
EOF
}
}
```
See vra7_deployment resource examples [here] (examples/README.md)

## Execution
These are the Terraform commands that can be used for the vRA plugin:
Expand All @@ -181,6 +37,18 @@ 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.

Upgrading the provider
----------------------

The vra7 provider doesn't upgrade automatically once you've started using it. After a new release you can run

```bash
terraform init -upgrade
```

to upgrade to the latest stable version of the vra7 provider. See the [Terraform website](https://www.terraform.io/docs/configuration/providers.html#provider-versions)
for more information on provider upgrades, and how to set version constraints on your provider.

Building the provider
---------------------

Expand Down Expand Up @@ -212,29 +80,6 @@ $ $GOPATH/bin/terraform-provider-vra7
...
```

# Scripts

For some older installations prior to v0.2.0 the **update_resource_state.sh** may need to be run.

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
------------

Expand Down
19 changes: 0 additions & 19 deletions example/multi-machine/main.tf

This file was deleted.

4 changes: 0 additions & 4 deletions example/multi-machine/terraform.tfvars.sample

This file was deleted.

12 changes: 0 additions & 12 deletions example/multi-machine/variables.tf

This file was deleted.

4 changes: 0 additions & 4 deletions example/multi-machine/versions.tf

This file was deleted.

15 changes: 9 additions & 6 deletions example/remote-execute/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ provider "vra7" {
host = var.host
}

resource "vra7_deployment" "vm" {
resource "vra7_deployment" "this" {
catalog_item_name = var.catalog_item_name
reasons = var.description
description = var.description
Expand All @@ -17,20 +17,23 @@ resource "vra7_deployment" "vm" {
}

resource_configuration = {
"Machine.description" = var.description
"Machine.cpu" = var.cpu
"Machine.memory" = var.ram
"Machine.ip_address" = ""
component_name = "Machine"
configuration = {
description = var.description
cpu = var.cpu
memory = var.ram
}
}

wait_timeout = var.wait_timeout

// Connection settings
// Connection settings
connection {
host = self.resource_configuration["Machine.ip_address"]
host = self.resource_configuration[*].ip_address
user = var.ssh_user
password = var.ssh_password
type = ssh
}

// Extend volume to second disk
Expand Down
35 changes: 32 additions & 3 deletions example/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,40 @@ provider "vra7" {
host = var.host
}

resource "vra7_deployment" "machine" {
resource "vra7_deployment" "this" {
count = 1
catalog_item_name = "CentOS 7.0 x64"
resource_configuration = {
"Linux.cpu" = "2"
description = "this description"
reason = "this reason"
lease_days = 10

deployment_configuration = {
"blueprint_custom_property" = "This is a blueprint custom property"
}

resource_configuration {
component_name = "Linux 1"
cluster = 2
configuration = {
cpu = 2
memory = 2048
custom_property = "VM custom property"
security_tag = <<EOF
[
"dev_sg",
"prod_sg"
]
EOF
}
}

resource_configuration {
component_name = "Linux 2"
configuration = {
cpu = 2
memory = 1024
storage = 8
}
}
}

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 // indirect
github.com/hashicorp/terraform v0.12.6
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473
github.com/stretchr/testify v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions sdk/mock_data_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sdk

var (
requestTemplateResponse = `{
requestTemplateResponse = `{
"type":"com.vmware.vcac.catalog.domain.request.CatalogItemProvisioningRequest",
"catalogItemId":"feaedf73-560c-4612-a573-41667e017691",
"requestedFor":"fritz@coke.sqa-horizon.local",
Expand Down Expand Up @@ -1082,7 +1082,7 @@ var (
}
}`

resourceActionsResponse = `{
resourcesResponse = `{
"links":[
],
Expand Down
Loading

0 comments on commit 113ee5c

Please sign in to comment.