forked from aaabdelgany/terraform-test-random
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
51 lines (44 loc) · 895 Bytes
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "~> 3.4"
}
}
}
variable "number" {
type = number
nullable = false
default = 1
}
variable "length" {
type = number
nullable = false
default = 1
validation{
condition = var.length > 0
error_message = "length must be positive."
}
}
variable "prefixes" {
type = list(string)
nullable = false
default = []
}
locals {
prefix = length(var.prefixes) == 0? null : join("-",var.prefixes)
}
resource "random_pet" "pet" {
count = var.number
length = var.length
prefix = local.prefix
lifecycle {
precondition {
condition = local.prefix != ""
error_message = "prefix can't be an empty string!"
}
}
}
output "names" {
value = [for pet in random_pet.pet : pet.id]
}