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

Commit

Permalink
Added deployment destroy patch (#48)
Browse files Browse the repository at this point in the history
Signed-off-by: Acristinii Dan, INI-ONE-WSN-NET-NNI <Dan.Acristinii@swisscom.com>
  • Loading branch information
danacr authored Mar 10, 2020
1 parent ae97497 commit 9c401d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit 9c401d0

Please sign in to comment.