11package scaleway
22
33import (
4- "bytes"
5- "fmt"
6-
74 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
85 iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1"
96 "github.com/scaleway/scaleway-sdk-go/scw"
@@ -53,8 +50,8 @@ func flattenPermissionSetNames(permissions []string) *schema.Set {
5350
5451func expandPolicyRuleSpecs (d interface {}) []* iam.RuleSpecs {
5552 rules := []* iam.RuleSpecs (nil )
56- rawRules := d .(* schema. Set )
57- for _ , rawRule := range rawRules . List () {
53+ rawRules := d .([] interface {} )
54+ for _ , rawRule := range rawRules {
5855 mapRule := rawRule .(map [string ]interface {})
5956 rule := & iam.RuleSpecs {
6057 PermissionSetNames : expandPermissionSetNames (mapRule ["permission_set_names" ]),
@@ -70,32 +67,6 @@ func expandPolicyRuleSpecs(d interface{}) []*iam.RuleSpecs {
7067 return rules
7168}
7269
73- func iamPolicyRuleHash (v interface {}) int {
74- var buf bytes.Buffer
75- m , ok := v .(map [string ]interface {})
76-
77- if ! ok {
78- return 0
79- }
80-
81- if orgID , hasOrgID := m ["organization_id" ]; hasOrgID && orgID != nil {
82- buf .WriteString (fmt .Sprintf ("%s-" , orgID .(string )))
83- }
84- if projIDs , hasProjIDs := m ["project_ids" ]; hasProjIDs && projIDs != nil {
85- projIDList := projIDs .([]interface {})
86- for _ , projID := range projIDList {
87- buf .WriteString (fmt .Sprintf ("%s-" , projID .(string )))
88- }
89- }
90- if permSet , hasPermSet := m ["permission_set_names" ]; hasPermSet {
91- permSetNames := permSet .(* schema.Set )
92- for _ , permName := range permSetNames .List () {
93- buf .WriteString (fmt .Sprintf ("%s-" , permName .(string )))
94- }
95- }
96- return StringHashcode (buf .String ())
97- }
98-
9970func flattenPolicyRules (rules []* iam.Rule ) interface {} {
10071 rawRules := []interface {}(nil )
10172 for _ , rule := range rules {
@@ -113,5 +84,5 @@ func flattenPolicyRules(rules []*iam.Rule) interface{} {
11384 }
11485 rawRules = append (rawRules , rawRule )
11586 }
116- return schema . NewSet ( iamPolicyRuleHash , rawRules )
87+ return rawRules
11788}
0 commit comments