Files

55 lines
1.6 KiB
Terraform

resource "ovh_cloud_project_keypair" "deploy_key" {
service_name = var.ovh_service_name
name = "coolify_deploy_key"
public_key = var.ssh_public_key
region = var.region
}
# 1. Look up the hardware flavor ID dynamically using the flavor name
data "ovh_cloud_project_flavors" "flavor" {
service_name = var.ovh_service_name
region = var.region
name_filter = var.flavor_name
}
# 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 = [for addr in ovh_cloud_project_instance.coolify.addresses : addr.ip if addr.version == 4][0]
})
filename = "${path.module}/../ansible/inventory.ini"
}