feat(terraform): write provisioned IPv4 into dynamic ansible inventory
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
[coolify_vm]
|
||||||
|
${public_ip} ansible_user=debian
|
||||||
+18
-10
@@ -1,5 +1,4 @@
|
|||||||
## DATA SOURCES
|
# Gather facts
|
||||||
|
|
||||||
data "ovh_cloud_instance_flavors" "flavors" {
|
data "ovh_cloud_instance_flavors" "flavors" {
|
||||||
service_name = var.ovh_service_name
|
service_name = var.ovh_service_name
|
||||||
region = var.ovh_region
|
region = var.ovh_region
|
||||||
@@ -10,15 +9,13 @@ data "ovh_cloud_instance_images" "images" {
|
|||||||
region = var.ovh_region
|
region = var.ovh_region
|
||||||
}
|
}
|
||||||
|
|
||||||
## RESOURCES
|
|
||||||
|
|
||||||
resource "ovh_cloud_ssh_key" "ansible" {
|
resource "ovh_cloud_ssh_key" "ansible" {
|
||||||
service_name = var.ovh_service_name
|
service_name = var.ovh_service_name
|
||||||
name = "ansible-key"
|
name = "ansible-key"
|
||||||
public_key = var.ssh_public_key
|
public_key = var.ssh_public_key
|
||||||
}
|
}
|
||||||
|
|
||||||
# Provision the d2-2 Public Cloud Instance
|
# Provision a d2-2 Public Cloud instance
|
||||||
resource "ovh_cloud_instance" "coolify" {
|
resource "ovh_cloud_instance" "coolify" {
|
||||||
service_name = var.ovh_service_name
|
service_name = var.ovh_service_name
|
||||||
region = var.ovh_region
|
region = var.ovh_region
|
||||||
@@ -40,14 +37,25 @@ resource "ovh_cloud_instance" "coolify" {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
## OUTPUTS
|
# Fetch provisioned VM's public IPv4
|
||||||
|
locals {
|
||||||
output "public_ip" {
|
public_ip = one(flatten([
|
||||||
description = "The public IPv4 address of the provisioned OVHcloud VM"
|
|
||||||
value = one(flatten([
|
|
||||||
for net in ovh_cloud_instance.coolify.current_state.networks : [
|
for net in ovh_cloud_instance.coolify.current_state.networks : [
|
||||||
for addr in net.addresses : addr.ip
|
for addr in net.addresses : addr.ip
|
||||||
if addr.type == "FIXED" && addr.version == 4
|
if addr.type == "FIXED" && addr.version == 4
|
||||||
]
|
]
|
||||||
]))
|
]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Write IP to Ansible inventory
|
||||||
|
resource "local_file" "ansible_inventory" {
|
||||||
|
content = templatefile("${path.module}/../ansible/inventory.tpl", {
|
||||||
|
public_ip = local.public_ip
|
||||||
|
})
|
||||||
|
filename = "${path.module}/../ansible/inventory.ini"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "public_ip" {
|
||||||
|
description = "The public IPv4 address of the provisioned OVHcloud VM"
|
||||||
|
value = local.public_ip
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ terraform {
|
|||||||
source = "ovh/ovh"
|
source = "ovh/ovh"
|
||||||
version = "~> 2.19.0"
|
version = "~> 2.19.0"
|
||||||
}
|
}
|
||||||
|
local = {
|
||||||
|
source = "hashicorp/local"
|
||||||
|
version = "~> 2.9.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user