feat: working terraform configuration

This commit is contained in:
2026-08-13 15:58:13 +02:00
parent 1301b05977
commit 614a529af5
3 changed files with 138 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
## DATA SOURCES
# Fetch available images filtered by Linux
data "ovh_cloud_project_images" "images" {
service_name = var.ovh_service_name
region = var.ovh_region
os_type = "linux"
}
# Fetch the ID for the d2-2 flavor
data "ovh_cloud_project_flavors" "flavors" {
service_name = var.ovh_service_name
region = var.ovh_region
name_filter = var.ovh_flavor_name
}
locals {
# Find the exact image matching the image_name variable
image = one([
for img in data.ovh_cloud_project_images.images.images : img if img.name == var.image_name
])
# Retrieve the exact d2-2 flavor ID
flavor = one(data.ovh_cloud_project_flavors.flavors.flavors)
}
## RESOURCES
# Create/Register SSH public key in the project
resource "ovh_cloud_project_ssh_key" "vm_ssh_key" {
service_name = var.ovh_service_name
name = "ansible-ssh-key"
public_key = var.ssh_public_key
}
# Provision the d2-2 Public Cloud Instance
resource "ovh_cloud_project_instance" "d2-2-vm" {
service_name = var.ovh_service_name
region = var.ovh_region
name = var.project_name
billing_period = "hourly" # Alternatives: "hourly" or "monthly"
boot_from {
image_id = local.image.id
}
flavor {
flavor_id = local.flavor.id
}
ssh_key {
name = ovh_cloud_project_ssh_key.vm_ssh_key.name
}
# Attaches a public IPv4 interface to the VM
network {
public = true
}
}
## OUTPUTS
# Outputs the public IPv4 address assigned to the VM once created
output "instance_public_ip" {
value = [
for addr in ovh_cloud_project_instance.d2-2-vm.addresses : addr.ip if addr.version == 4
]
description = "The public IPv4 address of your Frankfurt VM"
}