Skip to content

Commit

Permalink
fixed availability set template
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan Belval committed Mar 30, 2020
1 parent f1ef833 commit 09e1ce4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
13 changes: 13 additions & 0 deletions modules/general/availability_set/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion modules/general/availability_set/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 6 additions & 1 deletion modules/general/availability_set/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "name" {
description = "Availability set name."
description = "availability set name."
type = string
}

Expand All @@ -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
}
1 change: 0 additions & 1 deletion modules/general/availability_set/versions.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

terraform {
required_version = ">= 0.12"
}
9 changes: 9 additions & 0 deletions templating/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 09e1ce4

Please sign in to comment.