infrastructure-as-code/openstack-tf/modules/liferay/liferay.tf

68 lines
2.3 KiB
Terraform
Raw Normal View History

2023-12-01 15:50:29 +01:00
#
# Liferay nodes
#
#
# Security group
#
resource "openstack_networking_secgroup_v2" "liferay_cluster_traffic" {
name = "liferay_cluster_traffic"
delete_default_rules = "true"
description = "Traffic between the Liferay cluster nodes"
}
resource "openstack_networking_secgroup_rule_v2" "traffic_between_liferay_nodes" {
count = var.liferay_data.vm_count
security_group_id = openstack_networking_secgroup_v2.liferay_cluster_traffic.id
description = "Traffic between liferay nodes"
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
remote_ip_prefix = join("/", [element(var.liferay_ip_addrs.*, count.index), "32"])
}
2023-12-01 15:50:29 +01:00
#
# Server group
#
resource "openstack_compute_servergroup_v2" "liferay" {
name = "liferay"
2023-12-01 17:01:40 +01:00
policies = [var.liferay_data.affinity_policy]
2023-12-01 15:50:29 +01:00
}
2023-12-01 17:01:40 +01:00
# Instance(s)
2023-12-01 15:50:29 +01:00
resource "openstack_compute_instance_v2" "liferay" {
count = var.liferay_data.vm_count
2023-12-01 17:01:40 +01:00
name = format("%s-%02d", var.liferay_data.srv_name, count.index + 1)
2023-12-01 15:50:29 +01:00
availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
2023-12-01 17:01:40 +01:00
flavor_name = var.liferay_data.vm_flavor
2023-12-01 15:50:29 +01:00
key_pair = module.ssh_settings.ssh_key_name
security_groups = [var.default_security_group_name, openstack_networking_secgroup_v2.liferay_cluster_traffic.name, "traffic_from_the_main_load_balancers", "restricted_web_service"]
2023-12-01 15:50:29 +01:00
scheduler_hints {
group = openstack_compute_servergroup_v2.liferay.id
}
block_device {
uuid = var.ubuntu_1804.uuid
source_type = "image"
2023-12-01 17:01:40 +01:00
volume_size = var.liferay_data.boot_vol_size
2023-12-01 15:50:29 +01:00
boot_index = 0
destination_type = "volume"
delete_on_termination = false
}
network {
name = var.main_private_network.name
fixed_ip_v4 = var.liferay_ip_addrs.* [count.index]
2023-12-01 15:50:29 +01:00
}
2023-12-01 17:01:40 +01:00
network {
name = var.shared_postgresql_server_data.network_name
}
2023-12-01 15:50:29 +01:00
user_data = file("${var.ubuntu1804_data_file}")
# 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.
key_pair, user_data, network
]
}
2023-12-01 15:50:29 +01:00
}