Skip to content

Commit

Permalink
fix: ignores data order
Browse files Browse the repository at this point in the history
  • Loading branch information
iru committed Feb 19, 2024
1 parent 1e45b97 commit de5c714
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
30 changes: 21 additions & 9 deletions sysdig/resource_sysdig_secure_cloud_auth_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"strings"
"time"

v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
cloudauth "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2/cloudauth/go"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
cloudauth "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2/cloudauth/go"
)

func resourceSysdigSecureCloudauthAccount() *schema.Resource {
Expand Down Expand Up @@ -608,9 +609,6 @@ This helper function converts the components data from []*cloudauth.AccountCompo
This is needed to set the value in cloudauthAccountToResourceData().
*/
func componentsToResourceData(components []*cloudauth.AccountComponent, dataComponentsOrder []string) []map[string]interface{} {
// In the resource data, SchemaComponent field is a list of component sets[] / block
// Hence we need to return this uber level list in same order to cloudauthAccountToResourceData
componentsList := []map[string]interface{}{}

allComponents := make(map[string]interface{})
for _, comp := range components {
Expand Down Expand Up @@ -726,14 +724,28 @@ func componentsToResourceData(components []*cloudauth.AccountComponent, dataComp
allComponents[comp.Instance] = componentBlock
}

// return componentsList only if there is any components data from *[]cloudauth.AccountComponent, else return nil
// In the resource data, SchemaComponent field is a list of component sets[] / block
// Hence we need to return this uber level list in same order to cloudauthAccountToResourceData
componentsList := []map[string]interface{}{}

if len(allComponents) > 0 {
// add the component blocks in same order to maintain ordering
for _, c := range dataComponentsOrder {
componentItem := allComponents[c].(map[string]interface{})

//if len(dataComponentsOrder) > 0 {
// // add the component blocks in same order to maintain ordering
// for _, c := range dataComponentsOrder {
// componentItem := allComponents[c].(map[string]interface{})
// componentsList = append(componentsList, componentItem)
// }
// return componentsList
//}

// if no ordering is provided, return all components in any order
for _, c := range allComponents {
componentItem := c.(map[string]interface{})
componentsList = append(componentsList, componentItem)
}
return componentsList

}

return nil
Expand Down
21 changes: 9 additions & 12 deletions sysdig/resource_sysdig_secure_cloud_auth_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ func TestAccGCPSecureCloudAuthAccountFC(t *testing.T) {
Config: secureGCPCloudAuthAccountWithFC(accID),
},
{
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"component"},
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down Expand Up @@ -213,10 +212,9 @@ func TestAccAzureSecureCloudAccountFC(t *testing.T) {
Config: secureAzureCloudAuthAccountWithFC(accID),
},
{
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"component"},
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down Expand Up @@ -277,10 +275,9 @@ func TestAccAzureSecureCloudAccountFCThreatDetection(t *testing.T) {
Config: secureAzureCloudAuthAccountWithFCThreatDetection(accID),
},
{
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"component"},
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down

0 comments on commit de5c714

Please sign in to comment.