Skip to content

Conversation

@alexevladgabriel
Copy link

Description

Make Server Types & Locations dynamic based on API endpoints provided by Hetzner Docs.

Type of Change

  • New module
  • New template
  • Bug fix
  • Feature/enhancement
  • Documentation
  • Other

Template Information

Path: registry/Excellencedev/templates/hetzner-linux

Testing & Validation

  • Tests pass (bun test)
  • Code formatted (bun fmt)
  • Changes tested locally

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

This PR modernizes the Hetzner template by replacing static location and server type configurations with dynamic data fetched from Hetzner Cloud API endpoints. This eliminates the need for manual maintenance of a local JSON file and ensures the template always reflects current Hetzner offerings.

Key Changes:

  • Added hashicorp/http provider to fetch data from Hetzner Cloud API
  • Replaced static location options with dynamic options built from API response
  • Replaced JSON file-based server types with dynamic API-fetched data
  • Implemented filtering to exclude deprecated server types automatically

Comment on lines +127 to +130
name = loc.name
city = loc.city
country = loc.country
description = loc.description
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The locations data transformation extracts a 'description' field that is never used. The description field is captured in the local variable but not utilized in the dynamic options or elsewhere in the configuration. Consider removing this unused field to keep the code clean and focused, or document its purpose if it's intended for future use.

Suggested change
name = loc.name
city = loc.city
country = loc.country
description = loc.description
name = loc.name
city = loc.city
country = loc.country

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +40
data "http" "hcloud_locations" {
url = "https://api.hetzner.cloud/v1/locations"

request_headers = {
Authorization = "Bearer ${var.hcloud_token}"
Accept = "application/json"
}
}

data "http" "hcloud_server_types" {
url = "https://api.hetzner.cloud/v1/server_types"

request_headers = {
Authorization = "Bearer ${var.hcloud_token}"
Accept = "application/json"
}
}
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The HTTP data sources will be fetched during every Terraform plan/apply operation, which could lead to performance issues and potential API rate limiting. Consider the following:

  1. These API calls execute during the plan phase, adding latency to workspace operations
  2. Frequent workspace operations could trigger Hetzner API rate limits
  3. Network failures would block workspace provisioning

Consider documenting this behavior and potential limitations, or explore caching mechanisms if supported by the Coder platform.

Copilot uses AI. Check for mistakes.
Comment on lines 43 to 61
data "coder_parameter" "hcloud_location" {
name = "hcloud_location"
display_name = "Hetzner Location"
description = "Select the Hetzner Cloud location for your workspace."
type = "string"
default = "fsn1"
option {
name = "DE Falkenstein"
value = "fsn1"
}
option {
name = "US Ashburn, VA"
value = "ash"
}
option {
name = "US Hillsboro, OR"
value = "hil"
}
option {
name = "SG Singapore"
value = "sin"
}
option {
name = "DE Nuremberg"
value = "nbg1"
}
option {
name = "FI Helsinki"
value = "hel1"

dynamic "option" {
for_each = local.hcloud_locations
content {
name = format(
"%s (%s, %s)",
upper(option.value.name),
option.value.city,
option.value.country
)
value = option.value.name
}
}
}
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The location parameter now lacks a default value, which was previously set to "fsn1". Without a default, users will be required to select a location explicitly when creating a workspace. Consider adding a default value to improve the user experience. You could either:

  1. Set a static default value (e.g., default = "fsn1")
  2. Use the first available location from the API response dynamically

Copilot uses AI. Check for mistakes.
Comment on lines +125 to +132
hcloud_locations = [
for loc in jsondecode(data.http.hcloud_locations.response_body).locations : {
name = loc.name
city = loc.city
country = loc.country
description = loc.description
}
]
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The jsondecode() operations on API responses lack error handling. If the API returns an error response (e.g., due to invalid token, rate limiting, or network issues), the jsondecode will fail with an unhelpful error message. Consider adding validation or try-catch logic to provide clearer error messages, or at minimum add comments documenting the expected response structure for troubleshooting purposes.

Copilot uses AI. Check for mistakes.
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.

1 participant