Skip to content

Commit 971762b

Browse files
author
iru
authored
test(cloud-auth-account): ignores data order and removes the ImportStateVerifyIgnore (#481)
* fix: ignores data order * chore: restore comopnent order and clarification-request * ci: ignore goland run
1 parent aeb9183 commit 971762b

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ junit-report.xml
4646
terraform-provider-sysdig
4747
oanc
4848
.vscode/settings.json
49+
50+
# goland .run
51+
.run/

sysdig/resource_sysdig_secure_cloud_auth_account.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2122
func resourceSysdigSecureCloudauthAccount() *schema.Resource {
@@ -608,9 +609,6 @@ This helper function converts the components data from []*cloudauth.AccountCompo
608609
This is needed to set the value in cloudauthAccountToResourceData().
609610
*/
610611
func 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

sysdig/resource_sysdig_secure_cloud_auth_account_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ func TestAccGCPSecureCloudAuthAccountFC(t *testing.T) {
7272
Config: secureGCPCloudAuthAccountWithFC(accID),
7373
},
7474
{
75-
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
76-
ImportState: true,
77-
ImportStateVerify: true,
78-
ImportStateVerifyIgnore: []string{"component"},
75+
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
76+
ImportState: true,
77+
ImportStateVerify: true,
7978
},
8079
},
8180
})
@@ -213,10 +212,9 @@ func TestAccAzureSecureCloudAccountFC(t *testing.T) {
213212
Config: secureAzureCloudAuthAccountWithFC(accID),
214213
},
215214
{
216-
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
217-
ImportState: true,
218-
ImportStateVerify: true,
219-
ImportStateVerifyIgnore: []string{"component"},
215+
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
216+
ImportState: true,
217+
ImportStateVerify: true,
220218
},
221219
},
222220
})
@@ -277,10 +275,9 @@ func TestAccAzureSecureCloudAccountFCThreatDetection(t *testing.T) {
277275
Config: secureAzureCloudAuthAccountWithFCThreatDetection(accID),
278276
},
279277
{
280-
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
281-
ImportState: true,
282-
ImportStateVerify: true,
283-
ImportStateVerifyIgnore: []string{"component"},
278+
ResourceName: "sysdig_secure_cloud_auth_account.sample-1",
279+
ImportState: true,
280+
ImportStateVerify: true,
284281
},
285282
},
286283
})

0 commit comments

Comments
 (0)