-
Notifications
You must be signed in to change notification settings - Fork 567
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
fuliu-zln
wants to merge
1
commit into
aliyun:master
Choose a base branch
from
fuliu-zln:feat/groupResource
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+672
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 之前说过很多次,针对bool和int类型的字段,不要用d.Get直接获取,要用d.GetOkExists判断获取,改! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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的吗?
There was a problem hiding this comment.
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的吗?
不是,不同情况,默认值不同
There was a problem hiding this comment.
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不加。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和衫也确认过,存在不设置有默认值的情况,因此,加computed符合预期