forked from crazynuxer/terraform-aws-resource-naming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
40 lines (33 loc) · 1.59 KB
/
main.tf
File metadata and controls
40 lines (33 loc) · 1.59 KB
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
locals {
# Randomly generated hexadecimal value should not exceed 16 characters.
max_byte_length = 8
# Remove trailing dash in case the user inputted one.
# Example:
# * var.name_prefix = "txtdata-app" --> prefix = "txtdata-app-"
# * var.name_prefix = "txtdata-app-" --> prefix = "txtdata-app-"
# * var.name_prefix = "txtdata-app--" --> prefix = "txtdata-app--"
prefix = "${substr(var.name_prefix, -1, 1) == "-" ? substr(var.name_prefix, 0, length(var.name_prefix)-1) : var.name_prefix}-"
prefix_length = "${length(local.prefix)}"
resource_max_character_length = "${lookup(local.max_character_length, var.resource_type, 0)}"
random_max_byte_length = "${(local.resource_max_character_length - length(local.prefix)) / 2}"
random_byte_length = "${min(local.max_byte_length, local.random_max_byte_length)}"
}
# Null Provider. This module was created on 2018/04/10
provider "null" {
version = "1.0.0"
}
# Random Provider. This module was created on 2018/04/10
provider "random" {
version = "1.2.0"
}
# Throws error when resource_type is not suppported by the module yet
resource "null_resource" "unsupported_resource_type" {
count = "${local.resource_max_character_length == 0 ? 1 : 0}"
"\n\nCurrently supported resource types: \n* ${join("\n* ", keys(local.max_character_length))}" = true
}
# Provides random id in hex format
resource "random_id" "this" {
prefix = "${local.prefix}"
byte_length = "${local.random_byte_length}"
keepers = "${var.keepers}"
}