Skip to content

Conversation

vishesh92
Copy link
Member

Fixes #157

@vishesh92 vishesh92 requested a review from Copilot August 25, 2025 11:54
Copilot

This comment was marked as outdated.

@vishesh92 vishesh92 force-pushed the port-forward-add-end-ports branch from eae02c6 to 9ab257d Compare August 25, 2025 12:01
@vishesh92 vishesh92 requested a review from Copilot August 25, 2025 12:02
@apache apache deleted a comment from Copilot AI Aug 25, 2025
@apache apache deleted a comment from Copilot AI Aug 25, 2025
Copilot

This comment was marked as outdated.

@vishesh92 vishesh92 force-pushed the port-forward-add-end-ports branch 2 times, most recently from a71ba2e to fc43f6c Compare August 25, 2025 12:12
@vishesh92 vishesh92 requested a review from Copilot August 25, 2025 12:12
Copilot

This comment was marked as outdated.

@vishesh92 vishesh92 closed this Aug 26, 2025
@vishesh92 vishesh92 reopened this Aug 26, 2025
@vishesh92 vishesh92 force-pushed the port-forward-add-end-ports branch from fc43f6c to 843a461 Compare August 26, 2025 08:27
@vishesh92 vishesh92 requested a review from Copilot August 26, 2025 08:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for port range forwarding in CloudStack by introducing optional end port parameters for both private and public ports. Previously, the port forward resource only supported single port forwarding.

Key changes:

  • Added private_end_port and public_end_port as optional fields to enable port range forwarding
  • Updated the resource creation logic to set end ports when specified
  • Modified the read operation to handle port ranges properly

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
website/docs/r/port_forward.html.markdown Updated documentation to describe new optional end port fields and clarified existing port field descriptions
cloudstack/resource_cloudstack_port_forward.go Added schema definitions for end port fields and implemented logic to handle port ranges in create and read operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested manually

resource "cloudstack_port_forward" "head_node_ssh" {
  ip_address_id = "20a23048-a6e8-4db9-a3c1-3966043838ff"

  forward {
    protocol           = "tcp"
    private_port       = "22"
    private_end_port   = "24"
    public_port        = "22"
    public_end_port    = "24"
    virtual_machine_id = "3d8b9cf8-44ed-4066-9e62-2f0b67560d0b"
  }


}
terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # cloudstack_port_forward.head_node_ssh will be created
  + resource "cloudstack_port_forward" "head_node_ssh" {
      + id            = (known after apply)
      + ip_address_id = "20a23048-a6e8-4db9-a3c1-3966043838ff"
      + managed       = false

      + forward {
          + private_end_port   = 24
          + private_port       = 22
          + protocol           = "tcp"
          + public_end_port    = 24
          + public_port        = 22
          + uuid               = (known after apply)
          + virtual_machine_id = "3d8b9cf8-44ed-4066-9e62-2f0b67560d0b"
            # (1 unchanged attribute hidden)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

cloudstack_port_forward.head_node_ssh: Creating...
cloudstack_port_forward.head_node_ssh: Creation complete after 5s [id=20a23048-a6e8-4db9-a3c1-3966043838ff]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
╭─ ~/Desktop/cloudstack-India-demo/cloudstack-terraform copy                                                                                           ✔ ╱ 10s ╱ Azure subscription 1  ╱ 02:30:48 PM 
╰─ terraform destroy
cloudstack_port_forward.head_node_ssh: Refreshing state... [id=20a23048-a6e8-4db9-a3c1-3966043838ff]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # cloudstack_port_forward.head_node_ssh will be destroyed
  - resource "cloudstack_port_forward" "head_node_ssh" {
      - id            = "20a23048-a6e8-4db9-a3c1-3966043838ff" -> null
      - ip_address_id = "20a23048-a6e8-4db9-a3c1-3966043838ff" -> null
      - managed       = false -> null

      - forward {
          - private_end_port   = 24 -> null
          - private_port       = 22 -> null
          - protocol           = "tcp" -> null
          - public_end_port    = 24 -> null
          - public_port        = 22 -> null
          - uuid               = "cc13cd3e-5283-405f-938c-e656290fc362" -> null
          - virtual_machine_id = "3d8b9cf8-44ed-4066-9e62-2f0b67560d0b" -> null
            # (1 unchanged attribute hidden)
        }
    }

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

cloudstack_port_forward.head_node_ssh: Destroying... [id=20a23048-a6e8-4db9-a3c1-3966043838ff]
cloudstack_port_forward.head_node_ssh: Destruction complete after 5s

Destroy complete! Resources: 1 destroyed.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@kiranchavala kiranchavala merged commit cbb254b into main Aug 29, 2025
45 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to add a range for port forwarding
3 participants