Skip to content

fix: GCE region selection displays complete names instead of characters#14953

Merged
dguido merged 1 commit intomasterfrom
fix/gce-region-selection
Jan 30, 2026
Merged

fix: GCE region selection displays complete names instead of characters#14953
dguido merged 1 commit intomasterfrom
fix/gce-region-selection

Conversation

@dguido
Copy link
Copy Markdown
Member

@dguido dguido commented Jan 30, 2026

Summary

  • Fix GCE region selection that displayed individual characters instead of complete region names
  • The Jinja2 template was building a string ("['africa-south1', ...]") instead of an actual list
  • Now follows the pattern used by other cloud providers (EC2, DigitalOcean, Linode, Hetzner)

Fixes #14944

Test plan

  • Run linters: ansible-lint roles/cloud-gce/tasks/prompts.yml && yamllint roles/cloud-gce/tasks/prompts.yml
  • Syntax check: ansible-playbook main.yml --syntax-check
  • Manual test with GCE credentials to verify region prompt shows proper names

🤖 Generated with Claude Code

The Jinja2 template was building a string that looked like a list
instead of an actual list. When Ansible iterated over this string,
it yielded one character per iteration, causing the region prompt
to display:
  1. [
  2. '
  3. a
  ...

Now follows the pattern used by other cloud providers (EC2, DigitalOcean,
etc.) by storing region objects directly and accessing .name property.

Fixes #14944

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dguido dguido requested a review from jackivanov as a code owner January 30, 2026 04:08
@dguido dguido merged commit 1ea11ee into master Jan 30, 2026
26 checks passed
@dguido dguido deleted the fix/gce-region-selection branch January 30, 2026 04:09
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Jan 30, 2026

Code Review

Summary

This PR correctly fixes the GCE region selection bug where individual characters were displayed instead of complete region names. The root cause was Jinja2 native mode treating the constructed string as a literal string instead of a list.

Analysis

Problem identification (✅ Correct)
The original code constructed a string representation of a list:

gce_regions: >-
  [{%- for region in gcp_compute_regions_info.resources | sort(attribute='name') -%}
      '{{ region.name }}'{% if not loop.last %},{% endif %}
  {%- endfor -%}]

This resulted in gce_regions being a string like "['africa-south1', 'asia-east1', ...]" instead of an actual list, causing the loop to iterate over individual characters.

Solution (✅ Correct)
The fix properly stores the actual list of region objects:

gce_regions: "{{ gcp_compute_regions_info.resources | sort(attribute='name') }}"

Code Quality

Follows established patterns (✅)

  • The approach matches the pattern used in roles/cloud-linode/tasks/prompts.yml:26
  • Similar structure to how DigitalOcean handles region data
  • Consistent with Ansible 12+ Jinja2 native mode behavior

Jinja2 native mode compatibility (✅)

  • As documented in CLAUDE.md, Ansible 12+ enables jinja2_native by default
  • The fix correctly avoids manually constructing string representations of data structures
  • Properly accesses object attributes (r.name) instead of treating items as strings

Loop conversion (✅)

  • Changed variable name from region to r in default_region calculation (line 45)
  • Correctly accesses r.name instead of just r throughout
  • All three references updated consistently (lines 46, 54, 66, 67)

Testing Observations

What was tested:

  • The PR description indicates manual testing planned with GCE credentials
  • No automated tests exist for cloud provider prompt logic

Verification needed:

  1. Confirm the region prompt displays proper names (e.g., "1. africa-south1")
  2. Verify default region (us-east1) is correctly identified
  3. Test that user selection correctly sets algo_region to the region name string

Potential Issues

None identified. The changes are minimal, focused, and follow the correct pattern.

Recommendations

  1. Testing: Consider adding a unit test that verifies region list handling, similar to the template rendering tests in tests/unit/test_template_rendering.py
  2. Documentation: The inline comment about Jinja2 native mode in CLAUDE.md makes this type of issue well-documented for future maintainers

Security Considerations

No security implications - this is a UI/UX fix for region selection prompts.

Performance Considerations

Performance impact is negligible - actually slightly better since we're not manually constructing strings.


Verdict: ✅ Approved

This is a clean, well-scoped fix that solves exactly the reported issue. The changes follow established patterns in the codebase and are compatible with Ansible 12+ requirements.

🤖 Generated with Claude Code

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.

Google Cloud invalid regions

1 participant