Skip to content

Commit 6338aa3

Browse files
committed
Working on adding IDs that get truncated before appending attributes
1 parent e03e6cf commit 6338aa3

File tree

4 files changed

+59
-19
lines changed

4 files changed

+59
-19
lines changed

main.tf

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,36 @@ module "namespace-org" {
2020
}
2121

2222
locals {
23-
attr = "${lower(format("%s", join(var.delimiter, compact(var.attributes))))}"
24-
env = "${lower(format("%s", var.environment))}"
25-
name_low = "${lower(format("%s", var.name))}"
26-
org = "${lower(format("%s", var.organization))}"
27-
id_env = "${module.namespace-env.value ? join(var.delimiter, list(local.env, local.name_low)) : local.name_low}"
28-
id_org = "${module.namespace-org.value ? join(var.delimiter, list(local.org, local.id_env)) : local.id_env}"
29-
id = "${length(local.attr) > 0 ? join(var.delimiter, list(local.id_org, local.attr)) : local.id_org}"
30-
id_20 = "${substr(replace(local.id,"_","-"),0,19 <= length(local.id) ? 19 : length(local.id))}"
31-
id_32 = "${substr(replace(local.id,"_","-"),0,31 <= length(local.id) ? 31 : length(local.id))}"
32-
/*
33-
id_attr_20= "${19 <= length(local.id) ?
34-
join(var.delimiter, substr(local.id_org,0,
35-
(19 <= length(local.id_org) ? 19 : length(local.id_org))
36-
- length(local.attr)
37-
), local.attr)
23+
attr = "${lower(format("%s", join(var.delimiter, compact(var.attributes))))}"
24+
env = "${lower(format("%s", var.environment))}"
25+
name_low = "${lower(format("%s", var.name))}"
26+
org = "${lower(format("%s", var.organization))}"
27+
id_env = "${module.namespace-env.value ? join(var.delimiter, list(local.env, local.name_low)) : local.name_low}"
28+
id_org = "${module.namespace-org.value ? join(var.delimiter, list(local.org, local.id_env)) : local.id_env}"
29+
id = "${length(local.attr) > 0 ? join(var.delimiter, list(local.id_org, local.attr)) : local.id_org}"
30+
id_20 = "${substr(replace(local.id,"_","-"),0,19 <= length(local.id) ? 19 : length(local.id))}"
31+
id_32 = "${substr(replace(local.id,"_","-"),0,31 <= length(local.id) ? 31 : length(local.id))}"
32+
# Fix calc
33+
org_attr_20 = "${(19 <= length(local.id_org) ? 19 - length(local.attr) : length(local.id_org) - length(local.attr))}"
34+
id_attr_20 = "${19 <= length(local.id) ?
35+
join(var.delimiter,
36+
list(
37+
substr(local.id_org,0,
38+
local.org_attr_20 >= 0 ? local.org_attr_20 : 0)
39+
),
40+
list(local.attr)
41+
)
42+
: local.id}"
43+
org_attr_32 = "${(31 <= length(local.id_org) ? 31 - length(local.attr) : length(local.id_org) - length(local.attr))}"
44+
id_attr_32 = "${31 <= length(local.id) ?
45+
join(var.delimiter,
46+
list(
47+
substr(local.id_org,0,
48+
local.org_attr_32 >= 0 ? local.org_attr_32 : 0)
49+
),
50+
list(local.attr)
51+
)
3852
: local.id}"
39-
#id_attr_32= "${19 <= length(local.id) ? local.id : }"
40-
#id_attr_20 trunc name-org then join attr - total max still 20
41-
#id_attr_32 if id >32 trunc name-org to 31 - attr, then join attr
42-
*/
4353

4454
#tags_asg list of maps
4555
#map("key", "interpolation1", "value", "value3", "propagate_at_launch", true),

outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ output "id_32" {
1919
description = "ID truncated to 32 characters"
2020
value = "${local.id_32}"
2121
}
22+
output "id_attr_20" {
23+
description = "ID truncated to 20 characters"
24+
value = "${local.id_attr_20}"
25+
}
26+
output "id_attr_32" {
27+
description = "ID truncated to 32 characters"
28+
value = "${local.id_attr_32}"
29+
}
2230
output "id_env" {
2331
description = "If env namespace enabled <env>-<name> else <name>"
2432
value = "${local.id_env}"
@@ -39,3 +47,10 @@ output "tags" {
3947
description = "Tags map merged with standard tags"
4048
value = "${local.tags}"
4149
}
50+
//debugging
51+
output "org_attr_20" {
52+
value = "${local.org_attr_20}"
53+
}
54+
output "org_attr_32" {
55+
value = "${local.org_attr_32}"
56+
}

test/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module "labels" {
66
organization = "CorpXyZ"
77
namespace-org = true
88
#attributes = ["role", "policy", "use", ""]
9+
attributes = ["8080"]
910
tags = "${map("Key", "Value")}"
1011
}
1112
module "labels-tags" {

test/outputs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ output "id_32" {
2222
description = "Name truncated to 32 characters"
2323
value = "${module.labels.id_32}"
2424
}
25+
output "id_attr_20" {
26+
description = "Name truncated to 20 characters"
27+
value = "${module.labels.id_attr_20}"
28+
}
29+
output "id_attr_32" {
30+
description = "Name truncated to 32 characters"
31+
value = "${module.labels.id_attr_32}"
32+
}
2533
output "id_env" {
2634
description = "If env namespace enabled <env>-<name> else <name>"
2735
value = "${module.labels.id_env}"
@@ -38,3 +46,9 @@ output "tags" {
3846
description = "Tags"
3947
value = "${module.labels.tags}"
4048
}
49+
output "org_attr_20" {
50+
value = "${module.labels.org_attr_20}"
51+
}
52+
output "org_attr_32" {
53+
value = "${module.labels.org_attr_32}"
54+
}

0 commit comments

Comments
 (0)