2023-11-29 18:01:34 +01:00
|
|
|
# Promertheus server. A floating IP is required
|
|
|
|
resource "openstack_blockstorage_volume_v3" "prometheus_data_vol" {
|
2023-11-30 19:48:49 +01:00
|
|
|
name = var.prometheus_server_data.vol_data_name
|
|
|
|
size = var.prometheus_server_data.vol_data_size
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_instance_v2" "prometheus_server" {
|
2023-11-30 19:48:49 +01:00
|
|
|
name = var.prometheus_server_data.name
|
|
|
|
availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
|
|
|
|
flavor_name = var.prometheus_server_data.flavor
|
|
|
|
key_pair = module.ssh_settings.ssh_key_name
|
|
|
|
security_groups = [var.default_security_group_name, openstack_networking_secgroup_v2.restricted_web.name, openstack_networking_secgroup_v2.prometheus_access_from_grafana.name]
|
2023-11-29 18:01:34 +01:00
|
|
|
block_device {
|
2023-11-30 19:48:49 +01:00
|
|
|
uuid = var.ubuntu_2204.uuid
|
2023-11-29 18:01:34 +01:00
|
|
|
source_type = "image"
|
|
|
|
volume_size = 10
|
|
|
|
boot_index = 0
|
|
|
|
destination_type = "volume"
|
|
|
|
delete_on_termination = false
|
|
|
|
}
|
|
|
|
|
|
|
|
network {
|
2023-11-30 19:48:49 +01:00
|
|
|
name = var.main_private_network.name
|
|
|
|
fixed_ip_v4 = var.basic_services_ip.prometheus
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
2023-11-30 19:48:49 +01:00
|
|
|
user_data = file("${var.ubuntu2204_data_file}")
|
2023-12-14 12:55:20 +01:00
|
|
|
# Do not replace the instance when the ssh key changes
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
|
|
|
# Ignore changes to tags, e.g. because a management agent
|
|
|
|
# updates these based on some ruleset managed elsewhere.
|
2023-12-19 14:51:53 +01:00
|
|
|
key_pair, user_data, network
|
2023-12-14 12:55:20 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_volume_attach_v2" "prometheus_data_attach_vol" {
|
|
|
|
instance_id = openstack_compute_instance_v2.prometheus_server.id
|
|
|
|
volume_id = openstack_blockstorage_volume_v3.prometheus_data_vol.id
|
2023-11-30 19:48:49 +01:00
|
|
|
device = var.prometheus_server_data.vol_data_device
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Floating IP and DNS record
|
|
|
|
resource "openstack_networking_floatingip_v2" "prometheus_server_ip" {
|
2023-11-30 19:48:49 +01:00
|
|
|
pool = var.floating_ip_pools.main_public_ip_pool
|
|
|
|
# The DNS association does not work because of a bug in the OpenStack API
|
|
|
|
description = "Prometheus server"
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_floatingip_associate_v2" "prometheus_server" {
|
|
|
|
floating_ip = openstack_networking_floatingip_v2.prometheus_server_ip.address
|
|
|
|
instance_id = openstack_compute_instance_v2.prometheus_server.id
|
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
2023-11-30 19:48:49 +01:00
|
|
|
prometheus_recordset_name = "${var.prometheus_server_data.name}.${var.dns_zone.zone_name}"
|
|
|
|
alertmanager_recordset_name = "alertmanager.${var.dns_zone.zone_name}"
|
2023-11-29 18:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_dns_recordset_v2" "prometheus_server_recordset" {
|
2023-11-30 19:48:49 +01:00
|
|
|
zone_id = var.dns_zone_id
|
2023-11-29 18:01:34 +01:00
|
|
|
name = local.prometheus_recordset_name
|
|
|
|
description = "Public IP address of the Prometheus server"
|
|
|
|
ttl = 8600
|
|
|
|
type = "A"
|
|
|
|
records = [openstack_networking_floatingip_v2.prometheus_server_ip.address]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_dns_recordset_v2" "alertmanager_server_recordset" {
|
2023-11-30 19:48:49 +01:00
|
|
|
zone_id = var.dns_zone_id
|
2023-11-29 18:01:34 +01:00
|
|
|
name = local.alertmanager_recordset_name
|
|
|
|
description = "Prometheus alertmanager"
|
|
|
|
ttl = 8600
|
|
|
|
type = "CNAME"
|
|
|
|
records = [local.prometheus_recordset_name]
|
|
|
|
}
|
2024-05-02 18:25:21 +02:00
|
|
|
|
|
|
|
output "prometheus_public_ip_address" {
|
|
|
|
value = openstack_networking_floatingip_v2.prometheus_server_ip.address
|
|
|
|
}
|
|
|
|
|
|
|
|
output "prometheus_server_hostname" {
|
|
|
|
value = openstack_dns_recordset_v2.prometheus_server_recordset.name
|
|
|
|
}
|
|
|
|
|