generated from pulumi/pulumi-tf-provider-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 8
/
transform.go
56 lines (48 loc) · 1.39 KB
/
transform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package transform
import (
"fmt"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
var hardCodedAlters = map[string][]string{
"tencentcloud_kms_keys": {"key_state", "KmsKeyState"},
"tencentcloud_kms_key": {"key_state", "KmsKeyState"},
"tencentcloud_tsf_task": {"task_state", "TsfTaskState"},
}
func GetConflictFieldOfCsharpModule(key string, fields map[string]*schema.Schema) map[string]string {
module, entity := ResolveModuleEntity(key)
result := map[string]string{}
if v, ok := hardCodedAlters[key]; ok {
result[v[0]] = v[1]
}
for field := range fields {
if entity == field {
result[field] = ToPascal(module) + ToPascal(field)
break
}
}
if len(result) == 0 {
return nil
}
return result
}
func ResolveModuleEntity(key string) (module, entity string) {
seps := strings.Split(key, "_")[1:] // tencentcloud_foo_bar -> ["foo", "bar"]
if len(seps) <= 1 {
return seps[0], "instance"
}
if prefix := "tencentcloud_api_gateway"; strings.HasPrefix(key, prefix) {
return "api_gateway", strings.Join(seps[2:], "_")
}
if prefix := "tencentcloud_private_dns"; strings.HasPrefix(key, prefix) {
return "private_dns", strings.Join(seps[2:], "_")
}
return seps[0], strings.Join(seps[1:], "_")
}
func ToPascal(s string) string {
result := ""
for _, v := range strings.Split(s, "_") {
result += fmt.Sprintf("%s%s", strings.ToUpper(v[0:1]), v[1:])
}
return result
}