Skip to content

Commit 97afc87

Browse files
dmettemmarkpeek
authored andcommitted
Fail if deployment update action requested but not avaialble
If the 'Update' action is not available on a deployment, and if there are changes noticed to inputs in the configuration file, instead of just logging the debug statement, command is now failed with the following error: noticed changes to inputs, but 'Update' action is not supported based on the current state of the deployment Signed-off-by: Deepak Mettem <[email protected]>
1 parent 44a1185 commit 97afc87

File tree

4 files changed

+74
-67
lines changed

4 files changed

+74
-67
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ go 1.14
55
require (
66
github.com/go-openapi/runtime v0.19.15
77
github.com/go-openapi/strfmt v0.19.5
8-
github.com/hashicorp/terraform-plugin-sdk v1.9.1
8+
github.com/hashicorp/terraform-plugin-sdk v1.12.0
99
github.com/vmware/vra-sdk-go v0.2.10
1010
)

go.sum

+9-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ github.com/go-openapi/validate v0.19.3 h1:PAH/2DylwWcIU1s0Y7k3yNmeAgWOcKrNE2Q7Ww
115115
github.com/go-openapi/validate v0.19.3/go.mod h1:90Vh6jjkTn+OT1Eefm0ZixWNFjhtOH7vS9k0lo6zwJo=
116116
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
117117
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
118+
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
118119
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
119120
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
120121
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
121122
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
123+
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
122124
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
123125
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
124126
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -178,10 +180,10 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8
178180
github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A=
179181
github.com/hashicorp/terraform-json v0.4.0 h1:KNh29iNxozP5adfUFBJ4/fWd0Cu3taGgjHB38JYqOF4=
180182
github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU=
181-
github.com/hashicorp/terraform-plugin-sdk v1.9.1 h1:AgHnd6yPCg7o57XWrv4L7tIMdF0KQpcZro1pDHF1Xbw=
182-
github.com/hashicorp/terraform-plugin-sdk v1.9.1/go.mod h1:C/AXwmDHqbc3h6URiHpIsVKrwV4PS0Sh0+VTaeEkShw=
183-
github.com/hashicorp/terraform-plugin-test v1.2.0 h1:AWFdqyfnOj04sxTdaAF57QqvW7XXrT8PseUHkbKsE8I=
184-
github.com/hashicorp/terraform-plugin-test v1.2.0/go.mod h1:QIJHYz8j+xJtdtLrFTlzQVC0ocr3rf/OjIpgZLK56Hs=
183+
github.com/hashicorp/terraform-plugin-sdk v1.12.0 h1:HPp65ShSsKUMPf6jD50UQn/xAjyrGVO4FxI63bvu+pc=
184+
github.com/hashicorp/terraform-plugin-sdk v1.12.0/go.mod h1:HiWIPD/T9HixIhQUwaSoDQxo4BLFdmiBi/Qz5gjB8Q0=
185+
github.com/hashicorp/terraform-plugin-test v1.3.0 h1:hU5LoxrOn9qvOo+LTKN6mSav2J+dAMprbdxJPEQvp4U=
186+
github.com/hashicorp/terraform-plugin-test v1.3.0/go.mod h1:QIJHYz8j+xJtdtLrFTlzQVC0ocr3rf/OjIpgZLK56Hs=
185187
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg=
186188
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
187189
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
@@ -235,6 +237,7 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
235237
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
236238
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
237239
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
240+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
238241
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
239242
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
240243
github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI=
@@ -250,6 +253,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
250253
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
251254
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
252255
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
256+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
253257
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
254258
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
255259
github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok=
@@ -330,6 +334,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
330334
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
331335
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
332336
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
337+
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
333338
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
334339
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
335340
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

vra/deployment_request.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func deploymentRequestSchema() *schema.Schema {
1010
return &schema.Schema{
1111
Type: schema.TypeSet,
1212
Computed: true,
13+
MaxItems: 1,
1314
Elem: &schema.Resource{
1415
Schema: map[string]*schema.Schema{
1516
"action_id": {

vra/resource_deployment.go

+63-62
Original file line numberDiff line numberDiff line change
@@ -547,82 +547,83 @@ func runDeploymentUpdateAction(d *schema.ResourceData, apiClient *client.Multicl
547547

548548
name := d.Get("name")
549549
if !updateAvailable {
550-
log.Printf("Update action is not available on the vra_deployment %s, hence new inputs are not applied", name)
551-
} else {
552-
var inputs = make(map[string]interface{})
553-
blueprintID, catalogItemID := "", ""
554-
if v, ok := d.GetOk("catalog_item_id"); ok {
555-
catalogItemID = v.(string)
556-
}
550+
return fmt.Errorf("noticed changes to inputs, but 'Update' action is not supported based on the current state of the deployment %s", name)
551+
}
552+
553+
// Continue if update action is available.
554+
var inputs = make(map[string]interface{})
555+
blueprintID, catalogItemID := "", ""
556+
if v, ok := d.GetOk("catalog_item_id"); ok {
557+
catalogItemID = v.(string)
558+
}
557559

558-
if v, ok := d.GetOk("blueprint_id"); ok {
559-
blueprintID = v.(string)
560+
if v, ok := d.GetOk("blueprint_id"); ok {
561+
blueprintID = v.(string)
562+
}
563+
564+
// If catalog_item_id is provided, get the catalog item schema deployment with the catalog item
565+
if catalogItemID != "" {
566+
catalogItemVersion := ""
567+
if v, ok := d.GetOk("catalog_item_version"); ok {
568+
catalogItemVersion = v.(string)
560569
}
561570

562-
// If catalog_item_id is provided, get the catalog item schema deployment with the catalog item
563-
if catalogItemID != "" {
564-
catalogItemVersion := ""
565-
if v, ok := d.GetOk("catalog_item_version"); ok {
566-
catalogItemVersion = v.(string)
571+
if v, ok := d.GetOk("inputs"); ok {
572+
// If the inputs are provided, get the schema from catalog item to convert the provided input values
573+
// to the type defined in the schema.
574+
inputsSchemaMap, err := getCatalogItemSchema(apiClient, catalogItemID, catalogItemVersion)
575+
if err != nil {
576+
return err
567577
}
568578

569-
if v, ok := d.GetOk("inputs"); ok {
570-
// If the inputs are provided, get the schema from catalog item to convert the provided input values
571-
// to the type defined in the schema.
572-
inputsSchemaMap, err := getCatalogItemSchema(apiClient, catalogItemID, catalogItemVersion)
573-
if err != nil {
574-
return err
575-
}
576-
577-
log.Printf("Inputs Schema: %v", inputsSchemaMap)
578-
inputTypesMap, err := getInputTypesMapFromCatalogItemSchema(inputsSchemaMap)
579-
if err != nil {
580-
return err
581-
}
582-
583-
log.Printf("InputTypesMap: %v", inputTypesMap)
584-
inputs, err = getInputsByType(v.(map[string]interface{}), inputTypesMap)
585-
if err != nil {
586-
return err
587-
}
588-
}
589-
} else if blueprintID != "" {
590-
blueprintVersion := ""
591-
if v, ok := d.GetOk("blueprint_version"); ok {
592-
blueprintVersion = v.(string)
579+
log.Printf("Inputs Schema: %v", inputsSchemaMap)
580+
inputTypesMap, err := getInputTypesMapFromCatalogItemSchema(inputsSchemaMap)
581+
if err != nil {
582+
return err
593583
}
594584

595-
if v, ok := d.GetOk("inputs"); ok {
596-
// If the inputs are provided, get the schema from blueprint to convert the provided input values
597-
// to the type defined in the schema.
598-
inputsSchemaMap, err := getBlueprintSchema(apiClient, blueprintID, blueprintVersion)
599-
if err != nil {
600-
return err
601-
}
602-
603-
log.Printf("Inputs Schema: %v", inputsSchemaMap)
604-
inputTypesMap, err := getInputTypesMapFromBlueprintInputsSchema(inputsSchemaMap)
605-
if err != nil {
606-
return err
607-
}
608-
609-
log.Printf("InputTypesMap: %v", inputTypesMap)
610-
inputs, err = getInputsByType(v.(map[string]interface{}), inputTypesMap)
611-
if err != nil {
612-
return err
613-
}
585+
log.Printf("InputTypesMap: %v", inputTypesMap)
586+
inputs, err = getInputsByType(v.(map[string]interface{}), inputTypesMap)
587+
if err != nil {
588+
return err
614589
}
615590
}
591+
} else if blueprintID != "" {
592+
blueprintVersion := ""
593+
if v, ok := d.GetOk("blueprint_version"); ok {
594+
blueprintVersion = v.(string)
595+
}
616596

617-
reason := "Updated deployment inputs from vRA provider for Terraform."
618-
err := runAction(d, apiClient, deploymentUUID, actionID, inputs, reason)
619-
if err != nil {
620-
return err
597+
if v, ok := d.GetOk("inputs"); ok {
598+
// If the inputs are provided, get the schema from blueprint to convert the provided input values
599+
// to the type defined in the schema.
600+
inputsSchemaMap, err := getBlueprintSchema(apiClient, blueprintID, blueprintVersion)
601+
if err != nil {
602+
return err
603+
}
604+
605+
log.Printf("Inputs Schema: %v", inputsSchemaMap)
606+
inputTypesMap, err := getInputTypesMapFromBlueprintInputsSchema(inputsSchemaMap)
607+
if err != nil {
608+
return err
609+
}
610+
611+
log.Printf("InputTypesMap: %v", inputTypesMap)
612+
inputs, err = getInputsByType(v.(map[string]interface{}), inputTypesMap)
613+
if err != nil {
614+
return err
615+
}
621616
}
617+
}
622618

623-
log.Printf("Finished updating vra_deployment %s with inputs", name)
619+
reason := "Updated deployment inputs from vRA provider for Terraform."
620+
err = runAction(d, apiClient, deploymentUUID, actionID, inputs, reason)
621+
if err != nil {
622+
return err
624623
}
625624

625+
log.Printf("Finished updating vra_deployment %s with inputs", name)
626+
626627
return nil
627628
}
628629

0 commit comments

Comments
 (0)