diff --git a/main.tf b/main.tf index 0f9fa75..55c8677 100644 --- a/main.tf +++ b/main.tf @@ -3,3 +3,14 @@ locals { suffix = "${join(var.separator, var.suffixes)}" separated_name = "${var.separator}${var.name}${var.separator}" } + +data "null_data_source" "names" { + count = var.nb_instances + inputs = { + result = var.nb_instances > 1 ? substr("${local.prefix}${local.separated_name}${count.index}${var.separator}${local.suffix}", 0, var.max_length) : substr("${local.prefix}${var.separator}${var.name}${var.separator}${local.suffix}", 0, var.max_length) + } +} + +locals { + results = data.null_data_source.names.*.outputs.result +} diff --git a/outputs.tf b/outputs.tf index 6779956..f5b34f7 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,4 +1,9 @@ output "result" { description = "The generated resource name." - value = substr("${local.prefix}${local.separated_name}${local.suffix}", 0, var.max_length) + value = local.results[0] +} + +output "results" { + description = "The generated resource names." + value = local.results } diff --git a/variables.tf b/variables.tf index 0cbb6d9..b69b742 100644 --- a/variables.tf +++ b/variables.tf @@ -3,6 +3,10 @@ variable "name" { type = string } +variable "nb_instances" { + default = 1 +} + variable "prefixes" { description = "List of prefixes to append in front of the resource name." type = list(string)