-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e4b00a3
Showing
8 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.tfstate | ||
*.tfstate.backup | ||
.terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Terraform module to simplify and expand boolean use | ||
=== | ||
|
||
Since Terraform currently doesn't have a boolean variable type, this provides a consistent handling. The list of true values is also expanded. | ||
|
||
Designed to simplify the use of booleans (especially where 1 variable is tested many times) and the using count to enable/disable resources. | ||
|
||
* Will handle any capitalization of the input value. | ||
* Will return 1 for any true value, 0 for anything else. | ||
* Current true values: true, t, 1, on, enable | ||
|
||
Example: If | ||
```hcl | ||
module "boolean" { | ||
source = "devops-workflow/boolean/local" | ||
value = "${var.boolean}" | ||
} | ||
var = "${module.boolean.value ? "true setting" : "false setting"}" | ||
``` | ||
|
||
Example: count for enabling/disabling a resource | ||
```hcl | ||
module enabled" { | ||
source = "devops-workflow/boolean/local" | ||
value = "${var.enabled}" | ||
} | ||
resource "resource_type" "resource_name" { | ||
count = "${module.enabled.value}" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
# Terraform module to simplify and expand boolean use | ||
# | ||
|
||
locals { | ||
l = "${lower(var.value)}" | ||
v1 = "${local.l == "true" ? 1 : 0}" | ||
v2 = "${local.v1 ? 1 : local.l == "t" ? 1 : 0}" | ||
v3 = "${local.v2 ? 1 : local.l == "1" ? 1 : 0}" | ||
v4 = "${local.v3 ? 1 : local.l == "on" ? 1 : 0}" | ||
v5 = "${local.v4 ? 1 : local.l == "enable" ? 1 : 0}" | ||
value = "${local.v5}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
output "value" { | ||
description = "1 if input was tested `true`, 0 otherwise" | ||
value = "${local.value}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Test cases | ||
=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
module "true" { | ||
source = "../" | ||
value = "true" | ||
} | ||
module "t" { | ||
source = "../" | ||
value = "t" | ||
} | ||
module "one" { | ||
source = "../" | ||
value = "1" | ||
} | ||
module "on" { | ||
source = "../" | ||
value = "on" | ||
} | ||
module "enable" { | ||
source = "../" | ||
value = "enable" | ||
} | ||
module "false" { | ||
source = "../" | ||
value = "false" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
output "true" { | ||
value = "${module.true.value}" | ||
} | ||
output "t" { | ||
value = "${module.t.value}" | ||
} | ||
output "one" { | ||
value = "${module.one.value}" | ||
} | ||
output "on" { | ||
value = "${module.on.value}" | ||
} | ||
output "enable" { | ||
value = "${module.enable.value}" | ||
} | ||
output "false" { | ||
value = "${module.false.value}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
variable "value" { | ||
description = "Value to test for truth" | ||
type = "string" | ||
} |