Skip to content

Commit

Permalink
resource/alicloud_ess_scaling_rule: optimize query rule
Browse files Browse the repository at this point in the history
  • Loading branch information
fuliu-zln committed Nov 8, 2024
1 parent 75f3180 commit dd67584
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 6 additions & 8 deletions alicloud/resource_alicloud_ess_scaling_rule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package alicloud

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -202,19 +203,16 @@ func resourceAliyunEssScalingRuleCreate(d *schema.ResourceData, meta interface{}
}
addDebug(request.GetActionName(), raw, request.RpcRequest, request)
response, _ := raw.(*ess.CreateScalingRuleResponse)
d.SetId(response.ScalingRuleId)

_, ok := d.GetOk("alarm_dimension")
d.SetId(fmt.Sprint("false", ":", response.ScalingRuleId))
if ok {
d.SetId(fmt.Sprint("true", ":", response.ScalingRuleId))
}
return resourceAliyunEssScalingRuleRead(d, meta)
}

func resourceAliyunEssScalingRuleRead(d *schema.ResourceData, meta interface{}) error {

//Compatible with older versions id
if strings.Contains(d.Id(), COLON_SEPARATED) {
parts, _ := ParseResourceId(d.Id(), 2)
d.SetId(parts[1])
}

client := meta.(*connectivity.AliyunClient)
essService := EssService{client}

Expand Down
8 changes: 7 additions & 1 deletion alicloud/service_alicloud_ess.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,13 @@ func (s *EssService) flattenVserverGroupList(vServerGroups []ess.VServerGroup) [
func (s *EssService) DescribeEssScalingRule(id string) (rule ess.ScalingRule, err error) {
request := ess.CreateDescribeScalingRulesRequest()
request.ScalingRuleId = &[]string{id}
request.ShowAlarmRules = "true"
request.ShowAlarmRules = "false"
if strings.Contains(id, COLON_SEPARATED) {
parts, _ := ParseResourceId(id, 2)
request.ScalingRuleId = &[]string{parts[1]}
request.ShowAlarmRules = requests.Boolean(parts[0])
id = parts[1]
}
request.RegionId = s.client.RegionId
raw, err := s.client.WithEssClient(func(essClient *ess.Client) (interface{}, error) {
return essClient.DescribeScalingRules(request)
Expand Down

0 comments on commit dd67584

Please sign in to comment.