Added accounting-dashboard-db
This commit is contained in:
parent
2bd632462d
commit
812b128dbd
|
@ -0,0 +1,150 @@
|
|||
# Define required providers
|
||||
terraform {
|
||||
required_version = ">= 0.14.0"
|
||||
required_providers {
|
||||
openstack = {
|
||||
source = "terraform-provider-openstack/openstack"
|
||||
version = "~> 1.53.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "terraform_remote_state" "privnet_dns_router" {
|
||||
backend = "local"
|
||||
|
||||
config = {
|
||||
path = "../project-setup/terraform.tfstate"
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Uses common_variables as module
|
||||
#
|
||||
module "common_variables" {
|
||||
source = "../../modules/common_variables"
|
||||
}
|
||||
|
||||
# Module used
|
||||
module "ssh_settings" {
|
||||
source = "../../modules/ssh-key-ref"
|
||||
}
|
||||
|
||||
|
||||
# Network
|
||||
resource "openstack_networking_network_v2" "accounting_dashboard_db_net" {
|
||||
name = var.accounting_dashboard_db_data.network_name
|
||||
admin_state_up = "true"
|
||||
external = "false"
|
||||
description = var.accounting_dashboard_db_data.network_description
|
||||
dns_domain = var.dns_zone.zone_name
|
||||
mtu = var.common_variables.mtu_size
|
||||
port_security_enabled = true
|
||||
shared = false
|
||||
region = var.common_variables.main_region
|
||||
}
|
||||
|
||||
# Subnet
|
||||
resource "openstack_networking_subnet_v2" "accounting_dashboard_db_subnet" {
|
||||
name = var.accounting_dashboard_db_data.subnet_name
|
||||
description = var.accounting_dashboard_db_data.subnet_description
|
||||
network_id = openstack_networking_network_v2.accounting_dashboard_db_net.id
|
||||
cidr = var.accounting_dashboard_db_data.network_cidr
|
||||
dns_nameservers = var.common_variables.resolvers_ip
|
||||
ip_version = 4
|
||||
enable_dhcp = true
|
||||
no_gateway = true
|
||||
allocation_pool {
|
||||
start = var.accounting_dashboard_db_data.allocation_pool_start
|
||||
end = var.accounting_dashboard_db_data.allocation_pool_end
|
||||
}
|
||||
}
|
||||
|
||||
# Security group
|
||||
resource "openstack_networking_secgroup_v2" "accounting_dashboard_db_access" {
|
||||
name = "access_to_the_accounting_dashboard_db_service"
|
||||
delete_default_rules = "true"
|
||||
description = "Access the accounting-dashboard-db service using the dedicated network"
|
||||
}
|
||||
|
||||
resource "openstack_networking_secgroup_rule_v2" "accounting_dashboard_db_access_from_dedicated_subnet" {
|
||||
security_group_id = openstack_networking_secgroup_v2.accounting_dashboard_db_access.id
|
||||
description = "Allow connections to port 5432 from the 192.168.2.0/22 network"
|
||||
direction = "ingress"
|
||||
ethertype = "IPv4"
|
||||
protocol = "tcp"
|
||||
port_range_min = 5432
|
||||
port_range_max = 5432
|
||||
remote_ip_prefix = var.accounting_dashboard_db_data.network_cidr
|
||||
}
|
||||
|
||||
# Block device
|
||||
resource "openstack_blockstorage_volume_v3" "accounting_dashboard_db_data_vol" {
|
||||
name = var.accounting_dashboard_db_data.vol_data_name
|
||||
size = var.accounting_dashboard_db_data.vol_data_size
|
||||
}
|
||||
|
||||
# Instance
|
||||
# change security group
|
||||
resource "openstack_compute_instance_v2" "accounting_dashboard_db_server" {
|
||||
name = var.accounting_dashboard_db_data.name
|
||||
availability_zone_hints = var.availability_zones_names.availability_zone_no_gpu
|
||||
flavor_name = var.accounting_dashboard_db_data.flavor
|
||||
key_pair = module.ssh_settings.ssh_key_name
|
||||
security_groups = [var.common_variables.default_security_group_name, openstack_networking_secgroup_v2.accounting_dashboard_db_access.name]
|
||||
block_device {
|
||||
uuid = var.ubuntu_2204.uuid
|
||||
source_type = "image"
|
||||
volume_size = 10
|
||||
boot_index = 0
|
||||
destination_type = "volume"
|
||||
delete_on_termination = false
|
||||
}
|
||||
|
||||
network {
|
||||
name = var.main_private_network.name
|
||||
}
|
||||
network {
|
||||
name = var.accounting_dashboard_db_data.network_name
|
||||
fixed_ip_v4 = var.accounting_dashboard_db_data.server_ip
|
||||
}
|
||||
|
||||
user_data = file("${var.common_variables.ubuntu2204_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
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
resource "openstack_compute_volume_attach_v2" "accounting_dashboard_db_data_attach_vol" {
|
||||
instance_id = openstack_compute_instance_v2.accounting_dashboard_db_server.id
|
||||
volume_id = openstack_blockstorage_volume_v3.accounting_dashboard_db_data_vol.id
|
||||
device = var.accounting_dashboard_db_data.vol_data_device
|
||||
depends_on = [openstack_compute_instance_v2.accounting_dashboard_db_server]
|
||||
}
|
||||
|
||||
locals {
|
||||
cname_target = "main-lb.${data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name}"
|
||||
}
|
||||
|
||||
#
|
||||
# Add DNS record/s
|
||||
#
|
||||
module "dns_records_create" {
|
||||
source = "../../modules/dns_resources"
|
||||
|
||||
dns_resources_map = {
|
||||
acccounting-dashboard-db-server = {
|
||||
zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id
|
||||
name = join(".", [var.accounting_dashboard_db_data.name, data.terraform_remote_state.privnet_dns_router.outputs.dns_zone.zone_name])
|
||||
description = "Accounting Dashboard DB Server"
|
||||
ttl = 8600
|
||||
type = "CNAME"
|
||||
records = [local.cname_target]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
provider "openstack" {
|
||||
cloud = "d4s-production"
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
# TODO
|
||||
# definire gli indirizzi ip statici da usare,
|
||||
# spostare la variabile sotto nelle common-variables se serve,
|
||||
# aggiungre sempre in common-variables il security-group per questo db
|
||||
# e le definizioni per la rete dedicata affinché sia condivisibile
|
||||
# con altri servizi
|
||||
|
||||
variable "accounting_dashboard_db_data" {
|
||||
type = map(string)
|
||||
default = {
|
||||
name = "accounting-dashboard-db-server"
|
||||
flavor = "m1.medium"
|
||||
vol_data_name = "accounting-dashboard-db-data"
|
||||
vol_data_size = "10"
|
||||
vol_data_device = "/dev/vdb"
|
||||
# vol_backup_name = ""
|
||||
# vol_backup_size = ""
|
||||
# vol_backup_device = ""
|
||||
network_name = "accounting-dashboard-db-net"
|
||||
network_description = "Network used to communicate with the accounting-dashboard-db service"
|
||||
network_cidr = "192.168.0.0/22"
|
||||
subnet_name = "accounting-dashboard-db-subnet"
|
||||
subnet_description = "Subnet used to connect to the accounting-dashboard-db service"
|
||||
allocation_pool_start = "192.168.0.100"
|
||||
allocation_pool_end = "192.168.3.254"
|
||||
server_ip = "192.168.0.5"
|
||||
server_cidr = "192.168.0.5/22"
|
||||
}
|
||||
}
|
|
@ -133,6 +133,8 @@ variable "shared_postgresql_server_data" {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
variable "haproxy_l7_data" {
|
||||
type = map(string)
|
||||
default = {
|
||||
|
|
Loading…
Reference in New Issue