Skip to content

fix(compute): prevent panic in google_compute_service_attachment target_service expansion#26765

Closed
raman1236 wants to merge 1 commit intohashicorp:mainfrom
raman1236:fix/22206-service-attachment-panic
Closed

fix(compute): prevent panic in google_compute_service_attachment target_service expansion#26765
raman1236 wants to merge 1 commit intohashicorp:mainfrom
raman1236:fix/22206-service-attachment-panic

Conversation

@raman1236
Copy link
Copy Markdown

Summary

Fixes #22206

When target_service is specified using a short resource name rather than a full self_link URL, expandComputeServiceAttachmentTargetService panics with index out of range because it splits the value by / and unconditionally accesses index 3.

Root Cause

The function used strings.Split(v, "/") and then accessed parts[3] without a bounds check. Short resource names that were passed via the .name attribute had fewer than 4 segments, causing a runtime panic.

Fix

Removed the overly strict URL validation that required 4+ URL segments. The value is now passed through directly, which is consistent with the existing DiffSuppressFunc that already accepts both short names and full self_link URLs.

Files Changed

  • google/services/compute/resource_compute_service_attachment.go — Modified expandComputeServiceAttachmentTargetService function

Testing

  • Compilation verified clean (go build)
  • go vet passes

…et_service expansion

When target_service is specified using a short name rather than a full
self_link URL, expandComputeServiceAttachmentTargetService would panic
with 'index out of range' because it split by '/' and unconditionally
accessed index 3.

Remove the overly strict URL validation. The value is passed through
directly, consistent with the DiffSuppressFunc that already accepts
both short names and full self_link URLs.

Fixes hashicorp#22206
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 5, 2026

This repository is generated by https://github.com/GoogleCloudPlatform/magic-modules. Any changes made directly to this repository will likely be overwritten. If you have further questions, please feel free to ping your reviewer or, internal employees, reach out to one of the engineers. Thank you!

@melinath
Copy link
Copy Markdown
Collaborator

melinath commented Apr 6, 2026

Hi @raman1236 - thanks for working on this! This is a generated repository, so the change will need to be made in magic-modules. This resource is generated from mmv1/products/compute/ServiceAttachment.yaml. We have a contribution guide that has more details & guidance! In particular, you may need to add custom resource code.

@melinath melinath closed this Apr 6, 2026
@raman1236
Copy link
Copy Markdown
Author

Resubmitted upstream to magic-modules: GoogleCloudPlatform/magic-modules#17390

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.

panic: runtime error: index out of range [-1]

3 participants