Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gc-ss opened this issue Apr 14, 2022 · 4 comments

Comments

@gc-ss
Copy link

gc-ss commented Apr 14, 2022

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
Copy link
Author

gc-ss commented Apr 14, 2022

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")

@github-actions
Copy link

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 github-actions bot added the stale label Oct 11, 2023
@apricote apricote removed the stale label Oct 12, 2023
@apricote
Copy link
Member

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

Copy link

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 github-actions bot added the stale label Jan 10, 2024
@jooola jooola added pinned and removed stale labels Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants