dheeraj12347 opened a new pull request, #356:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/356

   ## Description
   
   Fixes an issue with project-scoped VM lookup when creating a port forward.
   
   The `cloudstack_port_forward` resource supports a `project` attribute, but 
while creating a port forward, the target virtual machine was previously 
retrieved using only its VM ID:
   
   ```go
   vm, _, err := cs.VirtualMachine.GetVirtualMachineByID(
       forward["virtual_machine_id"].(string),
   )
   ```
   
   This lookup does not pass the project context from the port forward resource.
   
   When project-scoped resources are used with account-level credentials, the 
VM lookup may fail because the API request does not include the project context 
required to resolve the project-scoped VM.
   
   ### Changes
   
   The VM lookup in `createPortForward` has been updated to pass the configured 
project:
   
   ```go
   vm, _, err := cs.VirtualMachine.GetVirtualMachineByID(
       forward["virtual_machine_id"].(string),
       cloudstack.WithProject(d.Get("project").(string)),
   )
   ```
   
   This ensures that the project associated with the port forward resource is 
also used when resolving the target VM.
   
   ### Regression Test
   
   Added a new acceptance test:
   
   ```text
   TestAccCloudStackPortForward_project
   ```
   
   The test creates:
   
   1. A project-scoped network.
   2. A project-scoped VM attached to that network.
   3. A port forward with an explicitly configured project.
   4. A port-forward rule targeting the project-scoped VM.
   
   The test verifies that:
   
   * The port-forward resource is created successfully.
   * The configured project is correctly associated with the resource.
   * A forward rule is created.
   * The forward rule receives a UUID.
   
   ### Existing Project Handling
   
   The existing project-inheritance behavior remains unchanged.
   
   The new test specifically covers the case where the `project` is explicitly 
configured on the port-forward resource and the target VM is also 
project-scoped.
   
   ### Validation
   
   The following local checks were successfully completed:
   
   * `go test ./cloudstack` — **passed**
   * `go vet ./...` — **passed**
   * `git diff --check` — **passed**
   
   The targeted acceptance test was also attempted:
   
   ```bash
   TF_ACC=1 \
   CLOUDSTACK_API_URL=http://localhost:8080/client/api \
   CLOUDSTACK_API_KEY="$CLOUDSTACK_API_KEY" \
   CLOUDSTACK_SECRET_KEY="$CLOUDSTACK_SECRET_KEY" \
   go test ./cloudstack \
   -run '^TestAccCloudStackPortForward_project$' \
   -v \
   -timeout 30m
   ```
   
   However, the acceptance test could not proceed to the port-forward resource 
logic because the locally deployed CloudStack simulator did not contain the 
expected `Sandbox-simulator` zone.
   
   The failure occurred during network creation:
   
   ```text
   Error retrieving ID of zone Sandbox-simulator: No match found for 
Sandbox-simulator
   ```
   
   Therefore, the targeted acceptance test was blocked by the local simulator 
environment before the VM lookup and port-forward creation logic were reached.
   
   ### Related Issue
   
   Fixes #355
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to