diff --git a/modules/general/availability_set/main.tf b/modules/general/availability_set/main.tf index 8f29c82..89c28bb 100644 --- a/modules/general/availability_set/main.tf +++ b/modules/general/availability_set/main.tf @@ -3,5 +3,18 @@ module "availability_set" { name = var.name prefixes = var.prefixes suffixes = var.suffixes + separator = "-" max_length = 80 + nb_instances = var.nb_instances } + +data "null_data_source" "names" { + count = var.nb_instances + inputs = { + result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.availability_set.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.availability_set.result) + } +} + +locals { + results = data.null_data_source.names.*.outputs.result +} \ No newline at end of file diff --git a/modules/general/availability_set/outputs.tf b/modules/general/availability_set/outputs.tf index aa2cf84..6800c68 100644 --- a/modules/general/availability_set/outputs.tf +++ b/modules/general/availability_set/outputs.tf @@ -1,4 +1,9 @@ output "result" { description = "The generated availability set name." - value = regex("^[a-zA-Z0-9_-]*$", module.availability_set.result) + value = local.results[0] +} + +output "results" { + description = "The generated availability set names." + value = local.results } \ No newline at end of file diff --git a/modules/general/availability_set/variables.tf b/modules/general/availability_set/variables.tf index 74b104d..10f2ee8 100644 --- a/modules/general/availability_set/variables.tf +++ b/modules/general/availability_set/variables.tf @@ -1,5 +1,5 @@ variable "name" { - description = "Availability set name." + description = "availability set name." type = string } @@ -11,4 +11,9 @@ variable "prefixes" { variable "suffixes" { description = "List of suffixes to append at the end of the resource name." type = list(string) + default = [] +} + +variable "nb_instances" { + default = 1 } \ No newline at end of file diff --git a/modules/general/availability_set/versions.tf b/modules/general/availability_set/versions.tf index ac97c6a..d9b6f79 100644 --- a/modules/general/availability_set/versions.tf +++ b/modules/general/availability_set/versions.tf @@ -1,4 +1,3 @@ - terraform { required_version = ">= 0.12" } diff --git a/templating/data.json b/templating/data.json index f6967df..aaa377c 100644 --- a/templating/data.json +++ b/templating/data.json @@ -27,6 +27,15 @@ "separator": "-", "regex": "^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$" }, + { + "source": "../../../.", + "name": "availability_set", + "long_name": "availability set", + "category": "general", + "max_length": 80, + "separator": "-", + "regex": "^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$" + }, { "source": "../../../.", "name": "vm_linux",