From dd67584173f6a2c0817bb83285148bb972ed7c87 Mon Sep 17 00:00:00 2001 From: wb-zln530580 Date: Fri, 8 Nov 2024 17:58:00 +0800 Subject: [PATCH] resource/alicloud_ess_scaling_rule: optimize query rule --- alicloud/resource_alicloud_ess_scaling_rule.go | 14 ++++++-------- alicloud/service_alicloud_ess.go | 8 +++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/alicloud/resource_alicloud_ess_scaling_rule.go b/alicloud/resource_alicloud_ess_scaling_rule.go index 2dda15de5d1..40058c1446f 100644 --- a/alicloud/resource_alicloud_ess_scaling_rule.go +++ b/alicloud/resource_alicloud_ess_scaling_rule.go @@ -1,6 +1,7 @@ package alicloud import ( + "fmt" "strconv" "strings" @@ -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} diff --git a/alicloud/service_alicloud_ess.go b/alicloud/service_alicloud_ess.go index 83b201592a5..ae086ddc2b1 100644 --- a/alicloud/service_alicloud_ess.go +++ b/alicloud/service_alicloud_ess.go @@ -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)