Skip to content

Commit 7478900

Browse files
committed
Fix truncate calc. Improve doc
1 parent 6338aa3 commit 7478900

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ locals {
2929
id = "${length(local.attr) > 0 ? join(var.delimiter, list(local.id_org, local.attr)) : local.id_org}"
3030
id_20 = "${substr(replace(local.id,"_","-"),0,19 <= length(local.id) ? 19 : length(local.id))}"
3131
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))}"
32+
org_attr_20 = "${min(18 - length(local.attr), length(local.id_org))}"
3433
id_attr_20 = "${19 <= length(local.id) ?
3534
join(var.delimiter,
3635
list(
@@ -40,7 +39,7 @@ locals {
4039
list(local.attr)
4140
)
4241
: local.id}"
43-
org_attr_32 = "${(31 <= length(local.id_org) ? 31 - length(local.attr) : length(local.id_org) - length(local.attr))}"
42+
org_attr_32 = "${min(30 - length(local.attr), length(local.id_org))}"
4443
id_attr_32 = "${31 <= length(local.id) ?
4544
join(var.delimiter,
4645
list(
@@ -63,5 +62,6 @@ locals {
6362
"Environment", "${local.env}",
6463
"Organization", "${local.org}",
6564
"Terraform", "true"
66-
))}"
65+
)
66+
)}"
6767
}

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ output "id_32" {
2020
value = "${local.id_32}"
2121
}
2222
output "id_attr_20" {
23-
description = "ID truncated to 20 characters"
23+
description = "ID max size 20 characters by truncating `id_org` then appending `attributes`"
2424
value = "${local.id_attr_20}"
2525
}
2626
output "id_attr_32" {
27-
description = "ID truncated to 32 characters"
27+
description = "ID max size 32 characters by truncating `id_org` then appending `attributes`"
2828
value = "${local.id_attr_32}"
2929
}
3030
output "id_env" {

test/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module "labels" {
99
attributes = ["8080"]
1010
tags = "${map("Key", "Value")}"
1111
}
12+
13+
/*
1214
module "labels-tags" {
1315
source = "../"
1416
name = "CapMe"
@@ -26,7 +28,7 @@ module "labels-disabled" {
2628
organization = "CorpXyZ"
2729
enabled = false
2830
}
29-
/**/
31+
/*
3032
3133
module "labels-env" {
3234
source = "../"
@@ -52,3 +54,4 @@ module "labels-org-env" {
5254
namespace-env = true
5355
namespace-org = true
5456
}
57+
*/

test/outputs.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ output "environment" {
88
value = "${module.labels.environment}"
99
}
1010
output "id" {
11+
description = "Full combined ID"
1112
value = "${module.labels.id}"
1213
}
1314
output "name" {
14-
description = "Name"
15+
description = "Name lowercase"
1516
value = "${module.labels.name}"
1617
}
1718
output "id_20" {
18-
description = "Name truncated to 20 characters"
19+
description = "ID truncated to 20 characters"
1920
value = "${module.labels.id_20}"
2021
}
2122
output "id_32" {
22-
description = "Name truncated to 32 characters"
23+
description = "ID truncated to 32 characters"
2324
value = "${module.labels.id_32}"
2425
}
2526
output "id_attr_20" {
26-
description = "Name truncated to 20 characters"
27+
description = "ID max size 20 characters by truncating `id_org` then appending `attributes`"
2728
value = "${module.labels.id_attr_20}"
2829
}
2930
output "id_attr_32" {
30-
description = "Name truncated to 32 characters"
31+
description = "ID max size 32 characters by truncating `id_org` then appending `attributes`"
3132
value = "${module.labels.id_attr_32}"
3233
}
3334
output "id_env" {
@@ -43,7 +44,7 @@ output "organization" {
4344
value = "${module.labels.organization}"
4445
}
4546
output "tags" {
46-
description = "Tags"
47+
description = "Tags with standard tags added"
4748
value = "${module.labels.tags}"
4849
}
4950
output "org_attr_20" {

0 commit comments

Comments
 (0)