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

Added support for deployment destroy #48

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ resource "vra7_deployment" "example_machine2" {

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.
Expand Down
1 change: 1 addition & 0 deletions sdk/vra7_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
Component = "Component"
Reconfigure = "Reconfigure"
Destroy = "Destroy"
DeploymentDestroy = "Deployment Destroy"
)

// GetCatalogItemRequestTemplate - Call to retrieve a request template for a catalog item.
Expand Down
10 changes: 9 additions & 1 deletion vra7/resource_vra7_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ProviderSchema struct {
FailedMessage string
DeploymentConfiguration map[string]interface{}
ResourceConfiguration map[string]interface{}
DeploymentDestroy bool
}

func resourceVra7Deployment() *schema.Resource {
Expand Down Expand Up @@ -106,6 +107,10 @@ func resourceVra7Deployment() *schema.Resource {
Computed: true,
Elem: schema.TypeString,
},
"deployment_destroy": {
Type: schema.TypeBool,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -392,6 +397,8 @@ func resourceVra7DeploymentRead(d *schema.ResourceData, meta interface{}) error
//Terraform call - terraform destroy
func resourceVra7DeploymentDelete(d *schema.ResourceData, meta interface{}) error {
vraClient = meta.(*sdk.APIClient)
// Get client handle
p := readProviderConfiguration(d)
//Get requester machine ID from schema.dataresource
catalogItemRequestID := d.Id()
// Throw an error if request ID has no value or empty value
Expand Down Expand Up @@ -421,7 +428,7 @@ func resourceVra7DeploymentDelete(d *schema.ResourceData, meta interface{}) erro
var destroyEnabled bool
var destroyActionID string
for _, op := range resources.Operations {
if op.Name == sdk.Destroy {
if (p.DeploymentDestroy && op.Name == sdk.DeploymentDestroy) || (!p.DeploymentDestroy && op.Name == sdk.Destroy) {
destroyEnabled = true
destroyActionID = op.OperationID
break
Expand Down Expand Up @@ -624,6 +631,7 @@ func readProviderConfiguration(d *schema.ResourceData) *ProviderSchema {
FailedMessage: strings.TrimSpace(d.Get("failed_message").(string)),
ResourceConfiguration: d.Get("resource_configuration").(map[string]interface{}),
DeploymentConfiguration: d.Get("deployment_configuration").(map[string]interface{}),
DeploymentDestroy: d.Get("deployment_destroy").(bool),
}

log.Info("The values provided in the TF config file is: \n %v ", providerSchema)
Expand Down