This is an automated email from the ASF dual-hosted git repository. vishesh pushed a commit to branch port-forward-add-end-ports in repository https://gitbox.apache.org/repos/asf/cloudstack-terraform-provider.git
commit eae02c6bea0d6eed81123eeaaee4022b080f8abe Author: vishesh92 <[email protected]> AuthorDate: Mon Aug 25 17:22:06 2025 +0530 Allow specifying private end port & public end port for port forward rules --- cloudstack/resource_cloudstack_port_forward.go | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cloudstack/resource_cloudstack_port_forward.go b/cloudstack/resource_cloudstack_port_forward.go index cd93431..792a7c3 100644 --- a/cloudstack/resource_cloudstack_port_forward.go +++ b/cloudstack/resource_cloudstack_port_forward.go @@ -73,11 +73,21 @@ func resourceCloudStackPortForward() *schema.Resource { Required: true, }, + "private_end_port": { + Type: schema.TypeInt, + Optional: true, + }, + "public_port": { Type: schema.TypeInt, Required: true, }, + "public_end_port": { + Type: schema.TypeInt, + Optional: true, + }, + "virtual_machine_id": { Type: schema.TypeString, Required: true, @@ -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)) + } if vmGuestIP, ok := forward["vm_guest_ip"]; ok && vmGuestIP.(string) != "" { p.SetVmguestip(vmGuestIP.(string)) @@ -279,15 +295,31 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{}) return err } + privEndPort, err := strconv.Atoi(f.Privateendport) + if err != nil { + return err + } + pubPort, err := strconv.Atoi(f.Publicport) if err != nil { return err } + pubEndPort, err := strconv.Atoi(f.Publicendport) + if err != nil { + return err + } + // Update the values forward["protocol"] = f.Protocol forward["private_port"] = privPort forward["public_port"] = pubPort + if f.Privateendport != "" && f.Privateendport != f.Privateport { + forward["private_end_port"] = privEndPort + } + if f.Publicendport != "" && f.Publicendport != f.Publicport { + forward["public_end_port"] = pubEndPort + } forward["virtual_machine_id"] = f.Virtualmachineid // This one is a bit tricky. We only want to update this optional value
