Skip to content

Add nexthop parameter to cloudstack_static_route resource#284

Open
bhouse-nexthop wants to merge 7 commits intoapache:mainfrom
bhouse-nexthop:feature/static-route-nexthop
Open

Add nexthop parameter to cloudstack_static_route resource#284
bhouse-nexthop wants to merge 7 commits intoapache:mainfrom
bhouse-nexthop:feature/static-route-nexthop

Conversation

@bhouse-nexthop
Copy link
Collaborator

This change adds support for the nexthop parameter in static routes, which allows VPC-based routing without requiring a private gateway id.

Resource Changes:

  • Add nexthop and vpc_id optional parameters to schema
  • nexthop is mutually exclusive with gateway_id
  • When using nexthop, vpc_id is required
  • When using gateway_id, nexthop and vpc_id are not allowed
  • Update resource creation logic to support both routing methods:
    • Private Gateway routing (gateway_id)
    • VPC direct routing (nexthop + vpc_id)
  • Update Read function to maintain plan stability for both modes

Test Coverage:

  • Add comprehensive test coverage for both routing methods
  • Add testAccPreCheckStaticRouteNexthop helper to check CloudStack version
  • Automatically skip nexthop tests on CloudStack versions < 4.22.0
  • Version check uses CloudStack capabilities API
  • Tests are skipped (not failed) on older versions for backward compatibility
  • All acceptance tests passing (2/2)

Documentation:

  • Update documentation with examples for both routing methods
  • Document mutual exclusivity requirements
  • Note CloudStack 4.22+ requirement for nexthop support

CI/CD:

  • Add CloudStack 4.22.0.0 to acceptance test matrix
  • Ensures tests run on both old and new CloudStack versions

This change adds support for the nexthop parameter in static routes,
which allows VPC-based routing without requiring a private gateway.

Resource Changes:
- Add nexthop and vpc_id optional parameters to schema
- nexthop is mutually exclusive with gateway_id
- When using nexthop, vpc_id is required
- When using gateway_id, nexthop and vpc_id are not allowed
- Update resource creation logic to support both routing methods:
  - Private Gateway routing (gateway_id)
  - VPC direct routing (nexthop + vpc_id)
- Update Read function to maintain plan stability for both modes

Test Coverage:
- Add comprehensive test coverage for both routing methods
- Add testAccPreCheckStaticRouteNexthop helper to check CloudStack version
- Automatically skip nexthop tests on CloudStack versions < 4.22.0
- Version check uses CloudStack capabilities API
- Tests are skipped (not failed) on older versions for backward compatibility
- All acceptance tests passing (2/2)

Documentation:
- Update documentation with examples for both routing methods
- Document mutual exclusivity requirements
- Note CloudStack 4.22+ requirement for nexthop support

CI/CD:
- Add CloudStack 4.22.0.0 to acceptance test matrix
- Ensures tests run on both old and new CloudStack versions
Copy link
Contributor

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

Adds support for VPC direct static routing by introducing a nexthop + vpc_id mode in cloudstack_static_route, alongside the existing private gateway (gateway_id) mode.

Changes:

  • Extend cloudstack_static_route schema and CRUD to support nexthop and vpc_id with mutual exclusivity vs gateway_id.
  • Add acceptance coverage for the new routing mode plus a CloudStack-version precheck helper.
  • Update docs/examples and expand the acceptance test matrix to include CloudStack 4.22.0.0.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cloudstack/resource_cloudstack_static_route.go Adds nexthop + vpc_id arguments and wires them into Create/Read.
cloudstack/resource_cloudstack_static_route_test.go Adds acceptance test exercising the nexthop mode.
cloudstack/provider_test.go Adds a precheck helper that skips nexthop tests on older CloudStack versions.
website/docs/r/static_route.html.markdown Documents both routing methods and their mutual exclusivity.
.github/workflows/acceptance.yml Adds CloudStack 4.22.0.0 to the acceptance test matrix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vishesh92
Copy link
Member

@bhouse-nexthop Can you check Copilot's comments?

- Add parseCloudStackVersion() to parse version strings into numeric values
- Add getCloudStackVersion() to retrieve version from API
- Add requireMinimumCloudStackVersion() for easy version checking in tests
- Refactor testAccPreCheckStaticRouteNexthop() to use new helpers
- These helpers can now be reused by other tests that need version checks
Document that the nexthop parameter requires CloudStack 4.22.0+
Add TestCheckResourceAttrPair to verify that vpc_id is properly persisted
in state and matches the created VPC resource
Add verifyStaticRouteParams() to validate that either gateway_id or
(nexthop + vpc_id) is provided before calling the API. This provides
clearer error messages at the Terraform level rather than letting
invalid configurations fail at the CloudStack API level.
The provider Meta() is not available during PreCheck, so we need to
create a CloudStack client directly using the environment variables.
Add test cases to verify that the parameter validation logic works correctly:
- Test missing both gateway_id and nexthop
- Test nexthop without vpc_id
- Test vpc_id without nexthop

These tests verify that the schema-level RequiredWith validation and
the custom verifyStaticRouteParams function work as expected.
@bhouse-nexthop
Copy link
Collaborator Author

@vishesh92 all comments addressed, please re-request Copilot review.

Copy link
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

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

clgtm. didn't test.

@vishesh92 vishesh92 added this to the v0.7.0 milestone Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants