From 2b9b1220e371b0ad4aada31a1e28e1dce389223b Mon Sep 17 00:00:00 2001 From: e2e Date: Wed, 7 Oct 2026 16:21:27 +0100 Subject: [PATCH] hpc: resolve project from the credential for the data sources (E2E fix2) --- hpc/ovh/main.tf | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/hpc/ovh/main.tf b/hpc/ovh/main.tf index 08ad93a..e3f37ca 100644 --- a/hpc/ovh/main.tf +++ b/hpc/ovh/main.tf @@ -4,20 +4,33 @@ // credentials and the project (OVH_CLOUD_PROJECT_SERVICE) reach the provider // from the runner environment, never from module inputs. +// The flavors/images data sources require an explicit service_name (unlike +// the resources, they do not fall back to the OVH_CLOUD_PROJECT_SERVICE +// runner variable when the attribute is an explicit null), so the project is +// resolved from the credential itself when no override is given: the +// per-account API keys of the platform are scoped to a single project. +data "ovh_cloud_projects" "all" { + count = var.project_id == null ? 1 : 0 +} + +locals { + service_name = var.project_id != null ? var.project_id : one(data.ovh_cloud_projects.all[0].projects[*].project_id) +} + data "ovh_cloud_project_flavors" "head" { - service_name = var.project_id + service_name = local.service_name name_filter = var.head_flavor region = var.region } data "ovh_cloud_project_flavors" "compute" { - service_name = var.project_id + service_name = local.service_name name_filter = var.compute_flavor region = var.region } data "ovh_cloud_project_images" "all" { - service_name = var.project_id + service_name = local.service_name region = var.region } @@ -37,14 +50,14 @@ locals { // assigned outside the DHCP pool; DHCP stays enabled so the instances // configure their private interface from the OpenStack metadata. resource "ovh_cloud_project_network_private" "cluster" { - service_name = var.project_id + service_name = local.service_name name = "${var.name_prefix}-hpc-${var.deployment_id}" regions = [var.region] vlan_id = var.vlan_id } resource "ovh_cloud_project_network_private_subnet" "cluster" { - service_name = var.project_id + service_name = local.service_name network_id = ovh_cloud_project_network_private.cluster.id region = var.region network = var.cluster_cidr @@ -69,7 +82,7 @@ locals { // through a dual-homed head node is not an option: the cloud's port // anti-spoofing silently drops the forwarded return traffic. resource "ovh_cloud_project_gateway" "egress" { - service_name = var.project_id + service_name = local.service_name name = "${var.name_prefix}-hpc-gw-${var.deployment_id}" model = var.gateway_model region = var.region @@ -81,13 +94,13 @@ resource "ovh_cloud_project_gateway" "egress" { // on destroy. The instance level ssh_key_create is avoided on purpose: keys it // creates outlive the instance and collide on the next deployment. resource "ovh_cloud_project_ssh_key" "admin" { - service_name = var.project_id + service_name = local.service_name name = "${var.name_prefix}-${var.deployment_id}-key" public_key = trimspace(tls_private_key.admin.public_key_openssh) } resource "ovh_cloud_project_instance" "head" { - service_name = var.project_id + service_name = local.service_name region = var.region billing_period = "hourly" name = local.head_hostname @@ -133,7 +146,7 @@ resource "ovh_cloud_project_instance" "head" { // addresses only carry the fixed private ip, the floating ip is matched // through the port it is associated with. data "ovh_cloud_project_floatingips" "all" { - service_name = var.project_id + service_name = local.service_name region_name = var.region depends_on = [ovh_cloud_project_instance.head] @@ -141,7 +154,7 @@ data "ovh_cloud_project_floatingips" "all" { resource "ovh_cloud_project_instance" "compute" { count = var.compute_node_count - service_name = var.project_id + service_name = local.service_name region = var.region billing_period = "hourly" name = local.compute_hostnames[count.index]