Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/alicloud_ess_scaling_group: add attributes of compensate_with_on_demand, capacity_options_on_demand_base_capacity, capacity_options_on_demand_percentage_above_base_capacity, capacity_options_compensate_with_on_demand and capacity_options_spot_auto_replace_on_demand. #8320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions alicloud/resource_alicloud_ess_scaling_group.go
Original file line number Diff line number Diff line change
@@ -186,6 +186,33 @@ func resourceAlicloudEssScalingGroup() *schema.Resource {
Optional: true,
Computed: true,
},
"compensate_with_on_demand": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compensate_with_on_demand,capacity_options_compensate_with_on_demand,capacity_options_spot_auto_replace_on_demand这三个bool类型的字段默认值都是true吗?capacity_options_on_demand_base_capacity和capacity_options_on_demand_percentage_above_base_capacity的默认值是非0的吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ompensate_with_on_demand,capacity_options_compensate_with_on_demand,capacity_options_spot_auto_replace_on_demand这三个bool类型的字段默认值都是true吗? 不是 某些情况用户没有设置,对应的属性,在后端服务是不会被设置上值的

capacity_options_on_demand_base_capacity和capacity_options_on_demand_percentage_above_base_capacity的默认值是非0的吗?
不是,不同情况,默认值不同

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然没有默认值就不要加computed!将computed注释掉,多跑几次第0步不设置这5个字段的单测,哪些字段报diff就加,不报diff不加。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和衫也确认过,存在不设置有默认值的情况,因此,加computed符合预期

Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"capacity_options_on_demand_base_capacity": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: IntBetween(0, 1000),
},
"capacity_options_on_demand_percentage_above_base_capacity": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: IntBetween(0, 100),
},
"capacity_options_compensate_with_on_demand": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"capacity_options_spot_auto_replace_on_demand": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"resource_group_id": {
Type: schema.TypeString,
Optional: true,
@@ -331,7 +358,9 @@ func resourceAliyunEssScalingGroupRead(d *schema.ResourceData, meta interface{})
if object["SpotInstancePools"] != nil {
d.Set("spot_instance_pools", object["SpotInstancePools"])
}

d.Set("spot_instance_remedy", object["SpotInstanceRemedy"])
d.Set("compensate_with_on_demand", object["CompensateWithOnDemand"])
d.Set("group_deletion_protection", object["GroupDeletionProtection"])
var polices []string
if len(object["RemovalPolicies"].(map[string]interface{})["RemovalPolicy"].([]interface{})) > 0 {
@@ -393,6 +422,22 @@ func resourceAliyunEssScalingGroupRead(d *schema.ResourceData, meta interface{})
}
}

if v := object["CapacityOptions"]; v != nil {
m := v.(map[string]interface{})
if m["OnDemandBaseCapacity"] != nil {
d.Set("capacity_options_on_demand_base_capacity", m["OnDemandBaseCapacity"])
}
if m["OnDemandPercentageAboveBaseCapacity"] != nil {
d.Set("capacity_options_on_demand_percentage_above_base_capacity", m["OnDemandPercentageAboveBaseCapacity"])
}
if m["CompensateWithOnDemand"] != nil {
d.Set("capacity_options_compensate_with_on_demand", m["CompensateWithOnDemand"])
}
if m["SpotAutoReplaceOnDemand"] != nil {
d.Set("capacity_options_spot_auto_replace_on_demand", m["SpotAutoReplaceOnDemand"])
}
}

if v := object["AlbServerGroups"]; v != nil {
result := make([]map[string]interface{}, 0)
if w, ok := d.GetOk("alb_server_group"); ok {
@@ -540,10 +585,40 @@ func resourceAliyunEssScalingGroupUpdate(d *schema.ResourceData, meta interface{
request["SpotInstancePools"] = requests.NewInteger(d.Get("spot_instance_pools").(int))
}

if d.HasChange("capacity_options_on_demand_base_capacity") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前说过很多次,针对bool和int类型的字段,不要用d.Get直接获取,要用d.GetOkExists判断获取,改!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if v, ok := d.GetOkExists("capacity_options_on_demand_base_capacity"); ok {
request["CapacityOptions.OnDemandBaseCapacity"] = requests.NewInteger(v.(int))
}
}

if d.HasChange("capacity_options_on_demand_percentage_above_base_capacity") {
if v, ok := d.GetOkExists("capacity_options_on_demand_percentage_above_base_capacity"); ok {
request["CapacityOptions.OnDemandPercentageAboveBaseCapacity"] = requests.NewInteger(v.(int))
}
}

if d.HasChange("capacity_options_compensate_with_on_demand") {
if v, ok := d.GetOkExists("capacity_options_compensate_with_on_demand"); ok {
request["CapacityOptions.CompensateWithOnDemand"] = requests.NewBoolean(v.(bool))
}
}

if d.HasChange("capacity_options_spot_auto_replace_on_demand") {
if v, ok := d.GetOkExists("capacity_options_spot_auto_replace_on_demand"); ok {
request["CapacityOptions.SpotAutoReplaceOnDemand"] = requests.NewBoolean(v.(bool))
}
}

if d.HasChange("spot_instance_remedy") {
request["SpotInstanceRemedy"] = requests.NewBoolean(d.Get("spot_instance_remedy").(bool))
}

if d.HasChange("compensate_with_on_demand") {
if v, ok := d.GetOkExists("compensate_with_on_demand"); ok {
request["CompensateWithOnDemand"] = requests.NewBoolean(v.(bool))
}
}

if d.HasChange("az_balance") {
request["AzBalance"] = requests.NewBoolean(d.Get("az_balance").(bool))
}
@@ -765,10 +840,29 @@ func buildAlicloudEssScalingGroupArgs(d *schema.ResourceData, meta interface{})
request["SpotInstancePools"] = v
}

if v, ok := d.GetOkExists("capacity_options_on_demand_base_capacity"); ok {
request["CapacityOptions.OnDemandBaseCapacity"] = v
}
if v, ok := d.GetOkExists("capacity_options_on_demand_percentage_above_base_capacity"); ok {
request["CapacityOptions.OnDemandPercentageAboveBaseCapacity"] = v
}

if v, ok := d.GetOkExists("capacity_options_compensate_with_on_demand"); ok {
request["CapacityOptions.CompensateWithOnDemand"] = v
}

if v, ok := d.GetOkExists("capacity_options_spot_auto_replace_on_demand"); ok {
request["CapacityOptions.SpotAutoReplaceOnDemand"] = v
}

if v, ok := d.GetOk("spot_instance_remedy"); ok {
request["SpotInstanceRemedy"] = v
}

if v, ok := d.GetOkExists("compensate_with_on_demand"); ok {
request["CompensateWithOnDemand"] = v
}

if v, ok := d.GetOk("health_check_type"); ok {
request["HealthCheckType"] = v
}
Loading