Skip to content

Commit

Permalink
Add utility module "if_then_list"
Browse files Browse the repository at this point in the history
For use in modules that use a lot of conditionals + list variables.
This module is a little more convenient than performing the workarounds
needed to use conditionals with list values.

See: hashicorp/terraform#12453
  • Loading branch information
bzub committed Oct 9, 2017
1 parent c383cd1 commit debdf26
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions if_then_list/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
output result {
/* value = "${null_resource.result.triggers.split}" */
value = "${local.result}"
}

locals {
then_string = "${join(var.separator, var.then)}"
else_string = "${join(var.separator, var.else)}"

result_string = "${
var.equality_condition_left == var.equality_condition_right
? local.then_string
: local.else_string
}"

result = "${split(var.separator, local.result_string)}"
}
4 changes: 4 additions & 0 deletions if_then_list/terraform.tfvars-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
equality_condition_left = "equal"
equality_condition_right = "noequal"
then = ["then", "list"]
else = ["else", "list", "else"]
22 changes: 22 additions & 0 deletions if_then_list/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
variable equality_condition_left {
description = ""
}

variable equality_condition_right {
description = ""
}

variable then {
description = ""
type = "list"
}

variable else {
description = ""
type = "list"
}

variable separator {
description = ""
default = "^:--:^"
}

0 comments on commit debdf26

Please sign in to comment.