@@ -40,18 +40,18 @@ func resourceAliCloudEssServerGroupAttachment() *schema.Resource {
4040 "port" : {
4141 Type : schema .TypeInt ,
4242 ForceNew : true ,
43- Required : true ,
43+ Optional : true ,
4444 },
4545 "type" : {
4646 Type : schema .TypeString ,
4747 ForceNew : true ,
48- ValidateFunc : StringInSlice ([]string {"ALB" , "NLB" }, false ),
48+ ValidateFunc : StringInSlice ([]string {"ALB" , "NLB" , "GWLB" }, false ),
4949 Required : true ,
5050 },
5151 "weight" : {
5252 Type : schema .TypeInt ,
5353 ForceNew : true ,
54- Required : true ,
54+ Optional : true ,
5555 },
5656 "force_attach" : {
5757 Type : schema .TypeBool ,
@@ -67,18 +67,35 @@ func resourceAliyunEssServerGroupAttachmentCreate(d *schema.ResourceData, meta i
6767 typeAttribute := d .Get ("type" ).(string )
6868 port := strconv .Itoa (formatInt (d .Get ("port" )))
6969
70+ if typeAttribute == "GWLB" {
71+ if _ , ok := d .GetOkExists ("weight" ); ok {
72+ return WrapError (Error ("When the type is set to GWLB, both weight and port are prohibited. Please remove the configurations for weight and port!" ))
73+ }
74+ if _ , ok := d .GetOkExists ("port" ); ok {
75+ return WrapError (Error ("When the type is set to GWLB, both weight and port are prohibited. Please remove the configurations for weight and port!" ))
76+ }
77+ }
78+
7079 client := meta .(* connectivity.AliyunClient )
7180 request := ess .CreateAttachServerGroupsRequest ()
7281 request .RegionId = client .RegionId
7382 request .ScalingGroupId = scalingGroupId
7483 request .ForceAttach = requests .NewBoolean (d .Get ("force_attach" ).(bool ))
7584 attachScalingGroupServerGroups := make ([]ess.AttachServerGroupsServerGroup , 0 )
76- attachScalingGroupServerGroups = append (attachScalingGroupServerGroups , ess.AttachServerGroupsServerGroup {
77- ServerGroupId : serverGroupId ,
78- Port : port ,
79- Weight : strconv .Itoa (formatInt (d .Get ("weight" ))),
80- Type : typeAttribute ,
81- })
85+ if typeAttribute == "GWLB" {
86+ attachScalingGroupServerGroups = append (attachScalingGroupServerGroups , ess.AttachServerGroupsServerGroup {
87+ ServerGroupId : serverGroupId ,
88+ Type : typeAttribute ,
89+ })
90+ } else {
91+ attachScalingGroupServerGroups = append (attachScalingGroupServerGroups , ess.AttachServerGroupsServerGroup {
92+ ServerGroupId : serverGroupId ,
93+ Port : port ,
94+ Weight : strconv .Itoa (formatInt (d .Get ("weight" ))),
95+ Type : typeAttribute ,
96+ })
97+ }
98+
8299 request .ServerGroup = & attachScalingGroupServerGroups
83100 wait := incrementalWait (1 * time .Second , 2 * time .Second )
84101
@@ -133,14 +150,24 @@ func resourceAliyunEssServerGroupAttachmentRead(d *schema.ResourceData, meta int
133150 }
134151
135152 for _ , v := range object .ServerGroups .ServerGroup {
136- if v .ServerGroupId == serverGroupId && v .Port == formatInt (port ) && v .Type == typeAttribute {
137- d .Set ("scaling_group_id" , object .ScalingGroupId )
138- d .Set ("type" , v .Type )
139- d .Set ("server_group_id" , v .ServerGroupId )
140- d .Set ("weight" , v .Weight )
141- d .Set ("port" , v .Port )
142- return nil
153+ if v .Type == "GWLB" {
154+ if v .ServerGroupId == serverGroupId && v .Type == typeAttribute {
155+ d .Set ("scaling_group_id" , object .ScalingGroupId )
156+ d .Set ("type" , v .Type )
157+ d .Set ("server_group_id" , v .ServerGroupId )
158+ return nil
159+ }
160+ } else {
161+ if v .ServerGroupId == serverGroupId && v .Port == formatInt (port ) && v .Type == typeAttribute {
162+ d .Set ("scaling_group_id" , object .ScalingGroupId )
163+ d .Set ("type" , v .Type )
164+ d .Set ("server_group_id" , v .ServerGroupId )
165+ d .Set ("weight" , v .Weight )
166+ d .Set ("port" , v .Port )
167+ return nil
168+ }
143169 }
170+
144171 }
145172 return WrapErrorf (NotFoundErr ("ServerGroup" , d .Id ()), NotFoundMsg , ProviderERROR )
146173}
@@ -155,11 +182,18 @@ func resourceAliyunEssServerGroupAttachmentDelete(d *schema.ResourceData, meta i
155182 request .ScalingGroupId = scalingGroupId
156183 request .ForceDetach = requests .NewBoolean (d .Get ("force_attach" ).(bool ))
157184 detachScalingGroupServerGroups := make ([]ess.DetachServerGroupsServerGroup , 0 )
158- detachScalingGroupServerGroups = append (detachScalingGroupServerGroups , ess.DetachServerGroupsServerGroup {
159- ServerGroupId : serverGroupId ,
160- Port : port ,
161- Type : typeAttribute ,
162- })
185+ if typeAttribute == "GWLB" {
186+ detachScalingGroupServerGroups = append (detachScalingGroupServerGroups , ess.DetachServerGroupsServerGroup {
187+ ServerGroupId : serverGroupId ,
188+ Type : typeAttribute ,
189+ })
190+ } else {
191+ detachScalingGroupServerGroups = append (detachScalingGroupServerGroups , ess.DetachServerGroupsServerGroup {
192+ ServerGroupId : serverGroupId ,
193+ Port : port ,
194+ Type : typeAttribute ,
195+ })
196+ }
163197 request .ServerGroup = & detachScalingGroupServerGroups
164198
165199 activityId := ""
0 commit comments