From da76e39ce334d38b7f10fee9810560afa4ff1af9 Mon Sep 17 00:00:00 2001 From: alessandrovitali Date: Wed, 12 Aug 2026 15:32:55 +0200 Subject: [PATCH] fix: terraform schema --- terraform/main.tf | 45 +++++++++++++++++++++++++++++++++++++------- terraform/outputs.tf | 2 +- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index c1ecbd2..18b4b1d 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -5,19 +5,50 @@ resource "ovh_cloud_project_keypair" "deploy_key" { region = var.region } -resource "ovh_cloud_project_instance" "coolify" { +# 1. Look up the hardware flavor ID dynamically using the flavor name +data "ovh_cloud_project_flavors" "flavor" { service_name = var.ovh_service_name - name = var.instance_name region = var.region - flavor_name = var.flavor_name - image_name = var.image_name - key_pair = ovh_cloud_project_keypair.deploy_key.name + name_filter = var.flavor_name } -# Generate inventory file for Ansible +# 2. Look up the image ID list dynamically for the region +data "ovh_cloud_project_images" "images" { + service_name = var.ovh_service_name + region = var.region +} + +resource "ovh_cloud_project_instance" "coolify" { + service_name = var.ovh_service_name + name = var.instance_name + region = var.region + billing_period = "hourly" + + # Use flavor block with the retrieved ID + flavor { + flavor_id = tolist(data.ovh_cloud_project_flavors.flavor.flavors)[0].id + } + + # Use boot_from block to filter and select the correct image ID + boot_from { + image_id = [for img in data.ovh_cloud_project_images.images.images : img.id if img.name == var.image_name][0] + } + + # Use network block to assign a public IP + network { + public = true + } + + # Use ssh_key block to attach the deploy key + ssh_key { + name = ovh_cloud_project_keypair.deploy_key.name + } +} + +# Generate inventory file for Ansible (using the updated addresses structure) resource "local_file" "ansible_inventory" { content = templatefile("${path.module}/../ansible/inventory.tpl", { - vps_ip = ovh_cloud_project_instance.coolify.ipv4_addresses[0] + vps_ip = [for addr in ovh_cloud_project_instance.coolify.addresses : addr.ip if addr.version == 4][0] }) filename = "${path.module}/../ansible/inventory.ini" } diff --git a/terraform/outputs.tf b/terraform/outputs.tf index 714bf18..c555709 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -1,6 +1,6 @@ output "vps_ip" { description = "The public IPv4 address of the Coolify VPS" - value = ovh_cloud_project_instance.coolify.ipv4_addresses[0] + value = [for addr in ovh_cloud_project_instance.coolify.addresses : addr.ip if addr.version == 4][0] } output "instance_id" {