terraform-provider-hcloud icon indicating copy to clipboard operation
terraform-provider-hcloud copied to clipboard

[Feature]: Enhance Data Source: hcloud_server_type to return locations for the server type

Open gc-ss opened this issue 2 years ago • 4 comments

What whould you like to see?

https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/data-sources/server_type at the moment returns some specs for the server type but leaves out rich data as available from the API: https://docs.hetzner.cloud/#server-types-get-a-server-type

One benefit of the rich data is to ensure:

  1. The requested server_type exists at the location
  2. The requested server_type prices at the location is within budget (price_hourly, price_monthly) and estimate the cost of running a stack

gc-ss avatar Apr 14 '22 22:04 gc-ss

Current workaround for 1:

def ensure_server_type_exists(token, server_type_name, server_location):
    server_type_name = server_type_name.lower()        
    response = httpx.get(f'https://api.hetzner.cloud/v1/server_types?name={server_type_name}', headers={"Authorization": f"Bearer {token}"})
    if response.status_code == HTTPStatus.OK.value:
        response = response.json()
        if response:
            _server_types = response.get('server_types', None)
            if _server_types:
                if len(_server_types) != 1:
                    raise ValueError(f"Expected to find unique server type {server_type_name}, instead found '{_server_types}'")
                else:        
                    _prices = _server_types[0].get('prices', None)
                    if _prices:
                        locations = {_price.get('location', None) for _price in _prices}
                        if server_location not in locations:
                            raise RuntimeError(f"Server type '{server_type_name}' unsupported at location '{server_location}'. Available at locations {locations}")
            else:
                raise ValueError(f"Did not find server type {server_type_name}")
                # TODO: ServerTypeUnknown exception
    else:
        raise RuntimeError(f"Failed to lookup server types")

gc-ss avatar Apr 14 '22 22:04 gc-ss

This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.

github-actions[bot] avatar Oct 11 '23 12:10 github-actions[bot]

Sounds like a good addition.

Right now the available server types are exposed in the data.hcloud_datacenter data source: https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/data-sources/datacenter#available_server_type_ids

apricote avatar Oct 12 '23 08:10 apricote

This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.

github-actions[bot] avatar Jan 10 '24 12:01 github-actions[bot]