Skip to content

Commit e4b00a3

Browse files
committed
first commit
0 parents  commit e4b00a3

File tree

8 files changed

+103
-0
lines changed

8 files changed

+103
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.tfstate
2+
*.tfstate.backup
3+
.terraform

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Terraform module to simplify and expand boolean use
2+
===
3+
4+
Since Terraform currently doesn't have a boolean variable type, this provides a consistent handling. The list of true values is also expanded.
5+
6+
Designed to simplify the use of booleans (especially where 1 variable is tested many times) and the using count to enable/disable resources.
7+
8+
* Will handle any capitalization of the input value.
9+
* Will return 1 for any true value, 0 for anything else.
10+
* Current true values: true, t, 1, on, enable
11+
12+
Example: If
13+
```hcl
14+
module "boolean" {
15+
source = "devops-workflow/boolean/local"
16+
value = "${var.boolean}"
17+
}
18+
19+
var = "${module.boolean.value ? "true setting" : "false setting"}"
20+
```
21+
22+
Example: count for enabling/disabling a resource
23+
```hcl
24+
module enabled" {
25+
source = "devops-workflow/boolean/local"
26+
value = "${var.enabled}"
27+
}
28+
29+
resource "resource_type" "resource_name" {
30+
count = "${module.enabled.value}"
31+
}
32+
```

main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Terraform module to simplify and expand boolean use
3+
#
4+
5+
locals {
6+
l = "${lower(var.value)}"
7+
v1 = "${local.l == "true" ? 1 : 0}"
8+
v2 = "${local.v1 ? 1 : local.l == "t" ? 1 : 0}"
9+
v3 = "${local.v2 ? 1 : local.l == "1" ? 1 : 0}"
10+
v4 = "${local.v3 ? 1 : local.l == "on" ? 1 : 0}"
11+
v5 = "${local.v4 ? 1 : local.l == "enable" ? 1 : 0}"
12+
value = "${local.v5}"
13+
}

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
output "value" {
3+
description = "1 if input was tested `true`, 0 otherwise"
4+
value = "${local.value}"
5+
}

test/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Test cases
2+
===

test/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
module "true" {
3+
source = "../"
4+
value = "true"
5+
}
6+
module "t" {
7+
source = "../"
8+
value = "t"
9+
}
10+
module "one" {
11+
source = "../"
12+
value = "1"
13+
}
14+
module "on" {
15+
source = "../"
16+
value = "on"
17+
}
18+
module "enable" {
19+
source = "../"
20+
value = "enable"
21+
}
22+
module "false" {
23+
source = "../"
24+
value = "false"
25+
}

test/outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
output "true" {
3+
value = "${module.true.value}"
4+
}
5+
output "t" {
6+
value = "${module.t.value}"
7+
}
8+
output "one" {
9+
value = "${module.one.value}"
10+
}
11+
output "on" {
12+
value = "${module.on.value}"
13+
}
14+
output "enable" {
15+
value = "${module.enable.value}"
16+
}
17+
output "false" {
18+
value = "${module.false.value}"
19+
}

variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "value" {
2+
description = "Value to test for truth"
3+
type = "string"
4+
}

0 commit comments

Comments
 (0)