Skip to content

Commit 7906ae3

Browse files
authored
fix: update irregular type (#1241)
* fix: update irregular type * fix: update type * fix: update type * fix: modify unit test * fix: modify unit test * fix: modify unit test Co-authored-by: arunma <arunma@tencent.com>
1 parent adb2eff commit 7906ae3

5 files changed

+43
-39
lines changed

tencentcloud/resource_tc_monitor_tmp_tke_cluster_agent.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ func resourceTencentCloudMonitorTmpTkeClusterAgent() *schema.Resource {
7373
Description: "Whether to enable the public network CLB.",
7474
},
7575
"in_cluster_pod_config": {
76-
Type: schema.TypeMap,
76+
Type: schema.TypeList,
77+
MaxItems: 1,
7778
Optional: true,
7879
Description: "Pod configuration for components deployed in the cluster.",
7980
Elem: &schema.Resource{
@@ -208,35 +209,38 @@ func resourceTencentCloudMonitorTmpTkeClusterAgentCreate(d *schema.ResourceData,
208209
prometheusClusterAgent.EnableExternal = helper.Bool(v.(bool))
209210
}
210211
if v, ok := dMap["in_cluster_pod_config"]; ok {
211-
podConfig := v.(map[string]interface{})
212212
var clusterAgentPodConfig *tke.PrometheusClusterAgentPodConfig
213-
if vv, ok := podConfig["host_net"]; ok {
214-
clusterAgentPodConfig.HostNet = helper.Bool(vv.(bool))
215-
}
216-
if vv, ok := podConfig["node_selector"]; ok {
217-
labelsList := vv.([]interface{})
218-
nodeSelectorKV := make([]*tke.Label, 0, len(labelsList))
219-
for _, labels := range labelsList {
220-
label := labels.(map[string]interface{})
221-
var kv tke.Label
222-
kv.Name = helper.String(label["name"].(string))
223-
kv.Value = helper.String(label["value"].(string))
224-
nodeSelectorKV = append(nodeSelectorKV, &kv)
213+
if len(v.([]interface{})) > 0 {
214+
podConfig := v.([]interface{})[0].(map[string]interface{})
215+
216+
if vv, ok := podConfig["host_net"]; ok {
217+
clusterAgentPodConfig.HostNet = helper.Bool(vv.(bool))
225218
}
226-
clusterAgentPodConfig.NodeSelector = nodeSelectorKV
227-
}
228-
if vv, ok := podConfig["tolerations"]; ok {
229-
tolerationList := vv.([]interface{})
230-
tolerations := make([]*tke.Toleration, 0, len(tolerationList))
231-
for _, t := range tolerationList {
232-
tolerationMap := t.(map[string]interface{})
233-
var toleration tke.Toleration
234-
toleration.Key = helper.String(tolerationMap["key"].(string))
235-
toleration.Operator = helper.String(tolerationMap["operator"].(string))
236-
toleration.Effect = helper.String(tolerationMap["effect"].(string))
237-
tolerations = append(tolerations, &toleration)
219+
if vv, ok := podConfig["node_selector"]; ok {
220+
labelsList := vv.([]interface{})
221+
nodeSelectorKV := make([]*tke.Label, 0, len(labelsList))
222+
for _, labels := range labelsList {
223+
label := labels.(map[string]interface{})
224+
var kv tke.Label
225+
kv.Name = helper.String(label["name"].(string))
226+
kv.Value = helper.String(label["value"].(string))
227+
nodeSelectorKV = append(nodeSelectorKV, &kv)
228+
}
229+
clusterAgentPodConfig.NodeSelector = nodeSelectorKV
230+
}
231+
if vv, ok := podConfig["tolerations"]; ok {
232+
tolerationList := vv.([]interface{})
233+
tolerations := make([]*tke.Toleration, 0, len(tolerationList))
234+
for _, t := range tolerationList {
235+
tolerationMap := t.(map[string]interface{})
236+
var toleration tke.Toleration
237+
toleration.Key = helper.String(tolerationMap["key"].(string))
238+
toleration.Operator = helper.String(tolerationMap["operator"].(string))
239+
toleration.Effect = helper.String(tolerationMap["effect"].(string))
240+
tolerations = append(tolerations, &toleration)
241+
}
242+
clusterAgentPodConfig.Tolerations = tolerations
238243
}
239-
clusterAgentPodConfig.Tolerations = tolerations
240244
}
241245
prometheusClusterAgent.InClusterPodConfig = clusterAgentPodConfig
242246
}

tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource "tencentcloud_monitor_tmp_tke_global_notification" "tmpGlobalNotificati
1010
enabled = true
1111
type = "webhook"
1212
web_hook = ""
13-
alert_manager = {
13+
alert_manager {
1414
url = ""
1515
cluster_type = ""
1616
cluster_id = ""
@@ -80,7 +80,7 @@ func resourceTencentCloudMonitorTmpTkeGlobalNotification() *schema.Resource {
8080
Description: "Web hook, if Type is `webhook`, this field is required.",
8181
},
8282
"alert_manager": {
83-
Type: schema.TypeMap,
83+
Type: schema.TypeList,
8484
Optional: true,
8585
Description: "Alert manager, if Type is `alertmanager`, this field is required.",
8686
Elem: &schema.Resource{
@@ -208,13 +208,13 @@ func resourceTencentCloudMonitorTmpTkeGlobalNotificationRead(d *schema.ResourceD
208208

209209
if *globalNotification.Enabled {
210210
_ = d.Set("instance_id", instanceId)
211-
alertManager := make(map[string]interface{})
211+
alertManager := make([]map[string]interface{}, 0)
212212
if globalNotification.AlertManager != nil {
213-
alertManager = map[string]interface{}{
213+
alertManager = append(alertManager, map[string]interface{}{
214214
"url": globalNotification.AlertManager.Url,
215215
"cluster_type": globalNotification.AlertManager.ClusterType,
216216
"cluster_id": globalNotification.AlertManager.ClusterId,
217-
}
217+
})
218218
}
219219

220220
var notifications []map[string]interface{}

tencentcloud/resource_tc_monitor_tmp_tke_global_notification_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ resource "tencentcloud_monitor_tmp_tke_global_notification" "basic" {
9494
notification {
9595
enabled = true
9696
type = "webhook"
97-
alert_manager = {
98-
"cluster_id" = ""
99-
"cluster_type" = ""
100-
"url" = ""
97+
alert_manager {
98+
cluster_id = ""
99+
cluster_type = ""
100+
url = ""
101101
}
102102
web_hook = ""
103103
repeat_interval = "5m"

website/docs/r/monitor_tmp_tke_cluster_agent.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The `agents` object supports the following:
4040
* `enable_external` - (Required, Bool) Whether to enable the public network CLB.
4141
* `region` - (Required, String) Limitation of region.
4242
* `external_labels` - (Optional, List) All metrics collected by the cluster will carry these labels.
43-
* `in_cluster_pod_config` - (Optional, Map) Pod configuration for components deployed in the cluster.
43+
* `in_cluster_pod_config` - (Optional, List) Pod configuration for components deployed in the cluster.
4444
* `not_install_basic_scrape` - (Optional, Bool) Whether to install the default collection configuration.
4545
* `not_scrape` - (Optional, Bool) Whether to collect indicators, true means drop all indicators, false means collect default indicators.
4646

website/docs/r/monitor_tmp_tke_global_notification.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "tencentcloud_monitor_tmp_tke_global_notification" "tmpGlobalNotificati
2020
enabled = true
2121
type = "webhook"
2222
web_hook = ""
23-
alert_manager = {
23+
alert_manager {
2424
url = ""
2525
cluster_type = ""
2626
cluster_id = ""
@@ -56,7 +56,7 @@ The `notification` object supports the following:
5656

5757
* `enabled` - (Required, Bool) Alarm notification switch.
5858
* `type` - (Required, String) Alarm notification type, Valid values: `amp`, `webhook`, `alertmanager`.
59-
* `alert_manager` - (Optional, Map) Alert manager, if Type is `alertmanager`, this field is required.
59+
* `alert_manager` - (Optional, List) Alert manager, if Type is `alertmanager`, this field is required.
6060
* `notify_way` - (Optional, Set) Alarm notification method, Valid values: `SMS`, `EMAIL`, `CALL`, `WECHAT`.
6161
* `phone_arrive_notice` - (Optional, Bool) Phone Alarm Reach Notification, NotifyWay is `CALL`, and this parameter is used.
6262
* `phone_circle_interval` - (Optional, Int) Telephone alarm off-wheel interval, NotifyWay is `CALL`, and this parameter is used.

0 commit comments

Comments
 (0)