Copilot commented on code in PR #204:
URL: 
https://github.com/apache/cloudstack-terraform-provider/pull/204#discussion_r2297904029


##########
cloudstack/resource_cloudstack_port_forward.go:
##########
@@ -175,6 +185,12 @@ func createPortForward(d *schema.ResourceData, meta 
interface{}, forward map[str
        // Create a new parameter struct
        p := cs.Firewall.NewCreatePortForwardingRuleParams(d.Id(), 
forward["private_port"].(int),
                forward["protocol"].(string), forward["public_port"].(int), 
vm.Id)
+       if forward["private_end_port"].(int) != 0 {
+               p.SetPrivateendport(forward["private_end_port"].(int))
+       }
+       if forward["public_end_port"].(int) != 0 {
+               p.SetPublicendport(forward["public_end_port"].(int))

Review Comment:
   This will panic if 'public_end_port' is nil. Since the field is optional, 
you should check if the value exists and is not nil before type assertion. 
Consider using: if val, ok := forward["public_end_port"]; ok && val != nil && 
val.(int) != 0 {
   ```suggestion
        if val, ok := forward["public_end_port"]; ok && val != nil && val.(int) 
!= 0 {
                p.SetPublicendport(val.(int))
   ```



##########
cloudstack/resource_cloudstack_port_forward.go:
##########
@@ -175,6 +185,12 @@ func createPortForward(d *schema.ResourceData, meta 
interface{}, forward map[str
        // Create a new parameter struct
        p := cs.Firewall.NewCreatePortForwardingRuleParams(d.Id(), 
forward["private_port"].(int),
                forward["protocol"].(string), forward["public_port"].(int), 
vm.Id)
+       if forward["private_end_port"].(int) != 0 {
+               p.SetPrivateendport(forward["private_end_port"].(int))

Review Comment:
   This will panic if 'private_end_port' is nil. Since the field is optional, 
you should check if the value exists and is not nil before type assertion. 
Consider using: if val, ok := forward["private_end_port"]; ok && val != nil && 
val.(int) != 0 {
   ```suggestion
        if val, ok := forward["private_end_port"]; ok && val != nil && 
val.(int) != 0 {
                p.SetPrivateendport(val.(int))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to