Skip to content

Commit

Permalink
resource/alicloud_alb_server_group: Fix bug while modify servers.desc…
Browse files Browse the repository at this point in the history
…ription. (#8167)
  • Loading branch information
ChenHanZhang authored Jan 23, 2025
1 parent 0c942e8 commit 481ac9f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
24 changes: 22 additions & 2 deletions alicloud/resource_alicloud_alb_server_group.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you!
package alicloud

import (
Expand Down Expand Up @@ -27,6 +26,7 @@ func resourceAliCloudAlbServerGroup() *schema.Resource {
Update: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},
CustomizeDiff: resourceAlbServerGroupCustomizeDiff,
Schema: map[string]*schema.Schema{
"connection_drain_config": {
Type: schema.TypeList,
Expand Down Expand Up @@ -194,10 +194,12 @@ func resourceAliCloudAlbServerGroup() *schema.Resource {
"server_ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"remote_ip_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"server_group_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -1023,7 +1025,9 @@ func resourceAliCloudAlbServerGroupUpdate(d *schema.ResourceData, meta interface
for _, dataLoop := range localData {
dataLoopTmp := dataLoop.(map[string]interface{})
dataLoopMap := make(map[string]interface{})
dataLoopMap["Description"] = dataLoopTmp["description"]
if dataLoopTmp["description"] != "" {
dataLoopMap["Description"] = dataLoopTmp["description"]
}
if dataLoopTmp["port"].(int) > 0 {
dataLoopMap["Port"] = dataLoopTmp["port"]
}
Expand Down Expand Up @@ -1122,3 +1126,19 @@ func resourceAliCloudAlbServerGroupDelete(d *schema.ResourceData, meta interface

return nil
}

func resourceAlbServerGroupCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
groupType := diff.Get("server_group_type").(string)
if groupType == "Fc" {
// Fc load balancers do not support vpc_id, protocol
if diff.Get("vpc_id") != "" {
return fmt.Errorf("fc server group type do not support vpc_id")
}

if diff.Get("protocol") != "" {
return fmt.Errorf("fc server group type do not support protocol")
}
}

return nil
}
19 changes: 19 additions & 0 deletions alicloud/resource_alicloud_alb_server_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ func TestAccAliCloudALBServerGroup_basic0(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"servers": []map[string]interface{}{
{
"server_id": "${alicloud_instance.default.id}",
"server_type": "Ecs",
"server_ip": "${alicloud_instance.default.private_ip}",
"port": "80",
"remote_ip_enabled": "false",
"weight": "20",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"servers.#": "1",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"servers": []map[string]interface{}{
Expand Down

0 comments on commit 481ac9f

Please sign in to comment.