Created generic modules
This commit is contained in:
parent
265f71f359
commit
58991984a3
|
@ -0,0 +1,64 @@
|
|||
|
||||
# Module used
|
||||
module "ssh_settings" {
|
||||
source = "../../modules/ssh-key-ref"
|
||||
}
|
||||
|
||||
# Module used
|
||||
module "common_variables" {
|
||||
source = "../../modules/common_variables"
|
||||
}
|
||||
|
||||
resource "openstack_blockstorage_volume_v3" "instance_data_volume" {
|
||||
for_each = var.instances_with_data_volume_map
|
||||
name = each.value.volume.name
|
||||
size = each.value.volume.size
|
||||
}
|
||||
|
||||
|
||||
# Generic smartgears_service instance
|
||||
resource "openstack_compute_instance_v2" "instance_with_data_volume" {
|
||||
for_each = var.instances_with_data_volume_map
|
||||
name = each.value.name
|
||||
availability_zone_hints = module.common_variables.availability_zone_no_gpu_name
|
||||
flavor_name = each.value.flavor
|
||||
key_pair = module.ssh_settings.ssh_key_name
|
||||
security_groups = each.value.security_groups
|
||||
block_device {
|
||||
uuid = each.value.image_ref.uuid
|
||||
source_type = "image"
|
||||
volume_size = 10
|
||||
boot_index = 0
|
||||
destination_type = "volume"
|
||||
delete_on_termination = false
|
||||
}
|
||||
|
||||
# Creates the networks according to input networks
|
||||
dynamic "network" {
|
||||
for_each = each.value.networks
|
||||
content {
|
||||
name = network.value
|
||||
}
|
||||
}
|
||||
|
||||
# Creates the scheduler_hints (i.e. server groups) according to input server_groups_ids
|
||||
dynamic "scheduler_hints" {
|
||||
for_each = each.value.server_groups_ids
|
||||
content {
|
||||
group = scheduler_hints.value
|
||||
}
|
||||
}
|
||||
|
||||
#user_data script used
|
||||
user_data = file("${each.value.image_ref.user_data_file}")
|
||||
}
|
||||
|
||||
|
||||
# Attach the additional volume
|
||||
resource "openstack_compute_volume_attach_v2" "attach_volume" {
|
||||
for_each = var.instances_with_data_volume_map
|
||||
instance_id = openstack_compute_instance_v2.instance_with_data_volume[each.key].id
|
||||
volume_id = openstack_blockstorage_volume_v3.instance_data_volume[each.key].id
|
||||
device = var.each.value.volume.device
|
||||
depends_on = [openstack_compute_instance_v2.instance_with_data_volume]
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
output "instances_with_data_volume_map" {
|
||||
value = var.instances_with_data_volume_map
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# Define required providers
|
||||
terraform {
|
||||
required_version = ">= 0.14.0"
|
||||
required_providers {
|
||||
openstack = {
|
||||
source = "terraform-provider-openstack/openstack"
|
||||
version = "~> 1.53.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
#Default smartgears_service is EMPTY. Override it to create a proper smartegears plan
|
||||
variable "instances_with_data_volume_map" {
|
||||
type = map(object({
|
||||
name = string
|
||||
description = string
|
||||
flavor = string
|
||||
networks = list(string)
|
||||
security_groups = list(string)
|
||||
server_groups_ids = list(string)
|
||||
image_ref = map(string)
|
||||
volume = map(string)
|
||||
}))
|
||||
default = {
|
||||
smartgears_service = {
|
||||
name = "",
|
||||
description = "",
|
||||
flavor = "",
|
||||
networks = [],
|
||||
security_groups = [],
|
||||
server_groups_ids = [],
|
||||
image_ref = {},
|
||||
volume = {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
# Module used
|
||||
module "ssh_settings" {
|
||||
source = "../../modules/ssh-key-ref"
|
||||
}
|
||||
|
||||
# Module used
|
||||
module "common_variables" {
|
||||
source = "../../modules/common_variables"
|
||||
}
|
||||
|
||||
# Generic smartgears_service instance
|
||||
resource "openstack_compute_instance_v2" "smartgears_service" {
|
||||
for_each = var.instances_without_data_volume_map
|
||||
name = each.value.name
|
||||
availability_zone_hints = module.common_variables.availability_zone_no_gpu_name
|
||||
flavor_name = each.value.flavor
|
||||
key_pair = module.ssh_settings.ssh_key_name
|
||||
security_groups = each.value.security_groups
|
||||
block_device {
|
||||
uuid = each.value.image_ref.uuid
|
||||
source_type = "image"
|
||||
volume_size = 10
|
||||
boot_index = 0
|
||||
destination_type = "volume"
|
||||
delete_on_termination = false
|
||||
}
|
||||
|
||||
# Creates the networks according to input networks
|
||||
dynamic "network" {
|
||||
for_each = each.value.networks
|
||||
content {
|
||||
name = network.value
|
||||
}
|
||||
}
|
||||
|
||||
# Creates the scheduler_hints (i.e. server groups) according to input server_groups_ids
|
||||
dynamic "scheduler_hints" {
|
||||
for_each = each.value.server_groups_ids
|
||||
content {
|
||||
group = scheduler_hints.value
|
||||
}
|
||||
}
|
||||
|
||||
#user_data script used
|
||||
user_data = file("${each.value.image_ref.user_data_file}")
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
output "instances_without_data_volume_map" {
|
||||
value = var.instances_without_data_volume_map
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# Define required providers
|
||||
terraform {
|
||||
required_version = ">= 0.14.0"
|
||||
required_providers {
|
||||
openstack = {
|
||||
source = "terraform-provider-openstack/openstack"
|
||||
version = "~> 1.53.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
# Default instances without data volume is EMPTY. Override it to create a proper instance plan
|
||||
variable "instances_without_data_volume_map" {
|
||||
type = map(object({
|
||||
name = string
|
||||
description = string
|
||||
flavor = string
|
||||
networks = list(string)
|
||||
security_groups = list(string)
|
||||
server_groups_ids = list(string)
|
||||
image_ref = map(string)
|
||||
}))
|
||||
default = {
|
||||
smartgears_service = {
|
||||
name = "",
|
||||
description = "",
|
||||
flavor = "",
|
||||
networks = [],
|
||||
security_groups = [],
|
||||
server_groups_ids = [],
|
||||
image_ref = {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue