/
data_source_alicloud_rds_class_details.go
131 lines (126 loc) · 3.57 KB
/
data_source_alicloud_rds_class_details.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package alicloud
import (
"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceAlicloudRdsClassDetails() *schema.Resource {
return &schema.Resource{
Read: dataSourceAlicloudRdsRdsClassDetailsRead,
Schema: map[string]*schema.Schema{
"commodity_code": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: StringInSlice([]string{"bards", "rds", "rords", "rds_rordspre_public_cn", "bards_intl", "rds_intl", "rords_intl", "rds_rordspre_public_intl"}, false),
},
"class_code": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"engine_version": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"engine": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: StringInSlice([]string{
string(MySQL),
string(SQLServer),
string(PostgreSQL),
string(MariaDB),
}, false),
},
"max_iombps": {
Type: schema.TypeString,
Computed: true,
},
"max_connections": {
Type: schema.TypeString,
Computed: true,
},
"class_group": {
Type: schema.TypeString,
Computed: true,
},
"cpu": {
Type: schema.TypeString,
Computed: true,
},
"instruction_set_arch": {
Type: schema.TypeString,
Computed: true,
},
"memory_class": {
Type: schema.TypeString,
Computed: true,
},
"max_iops": {
Type: schema.TypeString,
Computed: true,
},
"reference_price": {
Type: schema.TypeString,
Computed: true,
},
"category": {
Type: schema.TypeString,
Computed: true,
},
"db_instance_storage_type": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAlicloudRdsRdsClassDetailsRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
action := "DescribeClassDetails"
request := map[string]interface{}{
"SourceIp": client.SourceIp,
"RegionId": client.RegionId,
"CommodityCode": d.Get("commodity_code"),
"ClassCode": d.Get("class_code"),
"EngineVersion": d.Get("engine_version"),
"Engine": d.Get("engine"),
}
id := ""
if v, ok := d.GetOk("class_code"); ok {
id = v.(string)
}
var response map[string]interface{}
conn, err := client.NewRdsClient()
if err != nil {
return WrapError(err)
}
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2014-08-15"), StringPointer("AK"), nil, request, &runtime)
addDebug(action, response, request)
if err != nil {
return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_rds_class_details", action, AlibabaCloudSdkGoERROR)
}
resp, err := jsonpath.Get("$", response)
if err != nil {
return WrapErrorf(err, FailedGetAttributeMsg, action, "", response)
}
object := resp.(map[string]interface{})
d.SetId(id)
d.Set("max_iombps", object["MaxIOMBPS"])
d.Set("max_connections", object["MaxConnections"])
d.Set("class_group", object["ClassGroup"])
d.Set("cpu", object["Cpu"])
d.Set("instruction_set_arch", object["InstructionSetArch"])
d.Set("memory_class", object["MemoryClass"])
d.Set("max_iops", object["MaxIOPS"])
d.Set("reference_price", object["ReferencePrice"])
d.Set("category", object["Category"])
d.Set("db_instance_storage_type", object["DBInstanceStorageType"])
return nil
}