@@ -11,11 +11,12 @@ import (
1111 "strings"
1212 "time"
1313
14- v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
15- cloudauth "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2/cloudauth/go"
1614 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1715 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1816 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
17+
18+ v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
19+ cloudauth "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2/cloudauth/go"
1920)
2021
2122func resourceSysdigSecureCloudauthAccount () * schema.Resource {
@@ -608,9 +609,6 @@ This helper function converts the components data from []*cloudauth.AccountCompo
608609This is needed to set the value in cloudauthAccountToResourceData().
609610*/
610611func componentsToResourceData (components []* cloudauth.AccountComponent , dataComponentsOrder []string ) []map [string ]interface {} {
611- // In the resource data, SchemaComponent field is a list of component sets[] / block
612- // Hence we need to return this uber level list in same order to cloudauthAccountToResourceData
613- componentsList := []map [string ]interface {}{}
614612
615613 allComponents := make (map [string ]interface {})
616614 for _ , comp := range components {
@@ -726,14 +724,29 @@ func componentsToResourceData(components []*cloudauth.AccountComponent, dataComp
726724 allComponents [comp .Instance ] = componentBlock
727725 }
728726
729- // return componentsList only if there is any components data from *[]cloudauth.AccountComponent, else return nil
727+ // In the resource data, SchemaComponent field is a list of component sets[] / block
728+ // Hence we need to return this uber level list in same order to cloudauthAccountToResourceData
729+ componentsList := []map [string ]interface {}{}
730+
730731 if len (allComponents ) > 0 {
732+
731733 // add the component blocks in same order to maintain ordering
732- for _ , c := range dataComponentsOrder {
733- componentItem := allComponents [c ].(map [string ]interface {})
734+ // note-request; why is this needed?
735+ if len (dataComponentsOrder ) > 0 {
736+ for _ , c := range dataComponentsOrder {
737+ componentItem := allComponents [c ].(map [string ]interface {})
738+ componentsList = append (componentsList , componentItem )
739+ }
740+ return componentsList
741+ }
742+
743+ // if no ordering is provided, return all components in any order
744+ for _ , c := range allComponents {
745+ componentItem := c .(map [string ]interface {})
734746 componentsList = append (componentsList , componentItem )
735747 }
736748 return componentsList
749+
737750 }
738751
739752 return nil
0 commit comments