Repository navigation
Conversation
virtualRouterElementState and internalLbVmElementState returned a not-found error from inside the loop over the provider elements, so each only examined the first element and failed whenever the matching element was not at index 0. Move the not-found error after each loop and trigger it only when no element matched. Signed-off-by: Ramgopal Nagaboina <ramgopal.nagaboina.dev@gmail.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The localized changes correctly handle later matches and empty result sets without introducing regressions.
0 open findings
What changed in this PR
Corrects service-provider element lookups so all API results are searched before reporting failure.
Changes:
- Scans all virtual-router and internal-LB elements.
- Rejects missing or empty element IDs before configuration.
| File | Description |
|---|---|
cloudstack/resource_cloudstack_network_service_provider_state.go |
Corrects element lookup control flow. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
virtualRouterElementStateandinternalLbVmElementStatelook up the service provider element by iterating the list returned by the API, but the not-found error was returned inside the loop:So the lookup fails on the first element that does not match instead of scanning the rest, and an empty list falls through with an empty id into
ConfigureVirtualRouterElement. Move the error after the loop behind an empty-id check, so every element is scanned and a genuinely missing element returns a clear error. Same fix for the internal LB element lookup.Testing
go build ./...,go vet ./...andgo test ./cloudstack/pass (the resource's acceptance test skips withoutTF_ACC).There is no fails-before/passes-after acceptance test here: in a standard zone each provider has a single element, so the early return is not reached and the bug does not manifest end to end. The change is a localized control-flow correction in the element lookup, verified by the build, vet and the existing suite.