forked from KscSDK/terraform-provider-kingsoftcloud
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from kingsoftcloud/trunk
Trunk
- Loading branch information
Showing
12 changed files
with
328 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package helper | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
// generate a hash code that's value if from 'backend_server_group_id' | ||
// and its type is schema.SchemaSetFunc | ||
func HashFuncWithKeys(keys ...string) schema.SchemaSetFunc { | ||
return func(v interface{}) int { | ||
if v == nil { | ||
return hashcode.String("") | ||
} | ||
m := v.(map[string]interface{}) | ||
var buf bytes.Buffer | ||
|
||
for _, key := range keys { | ||
if vv, ok := m[key]; ok { | ||
switch vv.(type) { | ||
case string: | ||
if vv == "" { | ||
break | ||
} | ||
buf.WriteString(fmt.Sprintf("%s", strings.ToLower(vv.(string)))) | ||
case int: | ||
buf.WriteString(fmt.Sprintf("%d", vv.(int))) | ||
case float64: | ||
buf.WriteString(fmt.Sprintf("%d", int(vv.(float64)))) | ||
case bool: | ||
if vv.(bool) { | ||
buf.WriteString("1") | ||
} else { | ||
buf.WriteString("0") | ||
} | ||
case []interface{}: | ||
vvs := vv.([]interface{}) | ||
if len(vvs) < 1 { | ||
buf.WriteString("[]") | ||
} else { | ||
buf.WriteString("[") | ||
for _, vvv := range vvs { | ||
buf.WriteString(fmt.Sprintf("%s", strings.ToLower(vvv.(string)))) | ||
} | ||
buf.WriteString("]") | ||
} | ||
} | ||
} | ||
} | ||
return hashcode.String(buf.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.