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


##########
cloudstack/resource_cloudstack_port_forward.go:
##########
@@ -288,6 +306,21 @@ func resourceCloudStackPortForwardRead(d 
*schema.ResourceData, meta interface{})
                        forward["protocol"] = f.Protocol
                        forward["private_port"] = privPort
                        forward["public_port"] = pubPort
+                       // Only set end ports if they differ from start ports 
(indicating a range)
+                       if f.Privateendport != "" && f.Privateendport != 
f.Privateport {
+                               privEndPort, err := 
strconv.Atoi(f.Privateendport)
+                               if err != nil {
+                                       return err
+                               }
+                               forward["private_end_port"] = privEndPort
+                       }
+                       if f.Publicendport != "" && f.Publicendport != 
f.Publicport {
+                               pubEndPort, err := strconv.Atoi(f.Publicendport)
+                               if err != nil {
+                                       return err
+                               }
+                               forward["public_end_port"] = pubEndPort

Review Comment:
   The comparison between string port values should be done after converting to 
integers to ensure accurate comparison. String comparison might not work 
correctly for numeric values (e.g., '8' vs '10').
   ```suggestion
                        if f.Privateendport != "" {
                                privEndPort, err := 
strconv.Atoi(f.Privateendport)
                                if err != nil {
                                        return err
                                }
                                privPortInt, err := strconv.Atoi(f.Privateport)
                                if err != nil {
                                        return err
                                }
                                if privEndPort != privPortInt {
                                        forward["private_end_port"] = 
privEndPort
                                }
                        }
                        if f.Publicendport != "" {
                                pubEndPort, err := strconv.Atoi(f.Publicendport)
                                if err != nil {
                                        return err
                                }
                                pubPortInt, err := strconv.Atoi(f.Publicport)
                                if err != nil {
                                        return err
                                }
                                if pubEndPort != pubPortInt {
                                        forward["public_end_port"] = pubEndPort
                                }
   ```



##########
cloudstack/resource_cloudstack_port_forward.go:
##########
@@ -288,6 +306,21 @@ func resourceCloudStackPortForwardRead(d 
*schema.ResourceData, meta interface{})
                        forward["protocol"] = f.Protocol
                        forward["private_port"] = privPort
                        forward["public_port"] = pubPort
+                       // Only set end ports if they differ from start ports 
(indicating a range)
+                       if f.Privateendport != "" && f.Privateendport != 
f.Privateport {
+                               privEndPort, err := 
strconv.Atoi(f.Privateendport)
+                               if err != nil {
+                                       return err
+                               }
+                               forward["private_end_port"] = privEndPort
+                       }
+                       if f.Publicendport != "" && f.Publicendport != 
f.Publicport {
+                               pubEndPort, err := strconv.Atoi(f.Publicendport)
+                               if err != nil {
+                                       return err
+                               }
+                               forward["public_end_port"] = pubEndPort

Review Comment:
   Similar to the private port comparison, this string comparison should be 
done after converting to integers to ensure accurate numeric comparison.
   ```suggestion
                        if f.Publicendport != "" {
                                pubEndPort, err := strconv.Atoi(f.Publicendport)
                                if err != nil {
                                        return err
                                }
                                pubPortInt, err := strconv.Atoi(f.Publicport)
                                if err != nil {
                                        return err
                                }
                                if pubEndPort != pubPortInt {
                                        forward["public_end_port"] = pubEndPort
                                }
   ```



-- 
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