Skip to content

Conversation

vishesh92
Copy link
Member

Ref: apache/cloudstack-terraform-provider#158 (review)

This pull request improves the handling and code generation for parameters that require specific indexing formats in CloudStack API requests. The main changes address how map parameters are serialized, especially for commands and parameters that use zero-based indexing or require explicit index variables.

Improvements to parameter indexing logic:

  • Added updateVirtualMachine to the detailsRequireZeroIndex map, ensuring its details parameter uses zero-based indexing in generated code.
  • Introduced a new parametersRequireIndexing map to track parameters that always need index variables, even if the command uses zero indexing.

Adjustments to code generation:

  • Updated the code generation logic in generateConvertCode to use index variables only when required by the new maps, improving accuracy for map parameter serialization.
  • Refined the conditional logic for formatting key-value pairs, ensuring zero-based indexing is only applied when appropriate, and index variables are used when needed.

Bug fix in VM update parameter serialization:

  • Fixed the UpdateVirtualMachineParams.toURLValues method to always use zero-based indexing for the details parameter, aligning with API expectations.

Copilot

This comment was marked as outdated.

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.

Code looks good, any chance testing needs updating or can be added; it seems a bit of a hack and would benefit from saveguarding it.

@vishesh92
Copy link
Member Author

vishesh92 commented Sep 1, 2025

Code looks good, any chance testing needs updating or can be added; it seems a bit of a hack and would benefit from saveguarding it.

I can add a basic test in ci/ci_test.go for Upddate VM command. But it would be difficult to test for all params here.

@vishesh92 vishesh92 requested a review from Copilot September 2, 2025 05:44
Copy link

@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 pull request fixes the format of details map for update VM operations by improving parameter indexing logic in the CloudStack Terraform provider code generation. The changes ensure that the updateVirtualMachine command's details parameter uses zero-based indexing format instead of sequential indexing.

  • Added updateVirtualMachine to commands requiring zero-based indexing for details parameters
  • Introduced new parameter mapping to control when index variables are needed in code generation
  • Updated code generation logic to conditionally apply zero-based vs sequential indexing based on parameter requirements

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
generate/generate.go Added configuration maps and updated code generation logic to handle parameter indexing requirements
cloudstack/VirtualMachineService.go Updated UpdateVirtualMachineParams.toURLValues method to use zero-based indexing for details parameter

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

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.

2 participants