Open gc-ss opened 2 years ago
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")
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.
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
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.
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:
server_type
exists at thelocation
server_type
prices at thelocation
is within budget (price_hourly
,price_monthly
) and estimate the cost of running a stack