@@ -73,11 +73,23 @@ func resourceCloudStackPortForward() *schema.Resource {
7373 Required : true ,
7474 },
7575
76+ "private_end_port" : {
77+ Type : schema .TypeInt ,
78+ Optional : true ,
79+ Computed : true ,
80+ },
81+
7682 "public_port" : {
7783 Type : schema .TypeInt ,
7884 Required : true ,
7985 },
8086
87+ "public_end_port" : {
88+ Type : schema .TypeInt ,
89+ Optional : true ,
90+ Computed : true ,
91+ },
92+
8193 "virtual_machine_id" : {
8294 Type : schema .TypeString ,
8395 Required : true ,
@@ -175,6 +187,12 @@ func createPortForward(d *schema.ResourceData, meta interface{}, forward map[str
175187 // Create a new parameter struct
176188 p := cs .Firewall .NewCreatePortForwardingRuleParams (d .Id (), forward ["private_port" ].(int ),
177189 forward ["protocol" ].(string ), forward ["public_port" ].(int ), vm .Id )
190+ if val , ok := forward ["private_end_port" ]; ok && val != nil && val .(int ) != 0 {
191+ p .SetPrivateendport (val .(int ))
192+ }
193+ if val , ok := forward ["public_end_port" ]; ok && val != nil && val .(int ) != 0 {
194+ p .SetPublicendport (val .(int ))
195+ }
178196
179197 if vmGuestIP , ok := forward ["vm_guest_ip" ]; ok && vmGuestIP .(string ) != "" {
180198 p .SetVmguestip (vmGuestIP .(string ))
@@ -279,15 +297,32 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{})
279297 return err
280298 }
281299
300+ privEndPort , err := strconv .Atoi (f .Privateendport )
301+ if err != nil {
302+ return err
303+ }
304+
282305 pubPort , err := strconv .Atoi (f .Publicport )
283306 if err != nil {
284307 return err
285308 }
286309
310+ pubEndPort , err := strconv .Atoi (f .Publicendport )
311+ if err != nil {
312+ return err
313+ }
314+
287315 // Update the values
288316 forward ["protocol" ] = f .Protocol
289317 forward ["private_port" ] = privPort
290318 forward ["public_port" ] = pubPort
319+ // Only set end ports if they differ from start ports (indicating a range)
320+ if f .Privateendport != "" && f .Privateendport != f .Privateport {
321+ forward ["private_end_port" ] = privEndPort
322+ }
323+ if f .Publicendport != "" && f .Publicendport != f .Publicport {
324+ forward ["public_end_port" ] = pubEndPort
325+ }
291326 forward ["virtual_machine_id" ] = f .Virtualmachineid
292327
293328 // This one is a bit tricky. We only want to update this optional value
0 commit comments