Last active
June 8, 2016 22:16
-
-
Save imbriaco/594540615487eb9b59f54286e3d08f5c to your computer and use it in GitHub Desktop.
I'll take stupid Terraform tricks for $500, Alex
This file contains hidden or 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
module "my_instance" { | |
source = "../path/to/crazy_module.tf" | |
... | |
count = 1 | |
include_eip = "true" | |
} |
This file contains hidden or 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
resource "aws_instance" "instance" { | |
... | |
count = "${var.count}" | |
} | |
resource "aws_eip" "instance" { | |
depends_on = [ "aws_security_group.instance" ] | |
count = "${replace(replace(var.include_eip, "/\\Atrue\\z/", "1"), "/\\A[^1].*\\z/", "0") * var.count}" | |
} | |
resource "aws_eip_association" "instance" { | |
instance_id = "${element(aws_instance.instance.*.id, count.index)}" | |
allocation_id = "${element(aws_eip.instance.*.id, count.index)}" | |
count = "${replace(replace(var.include_eip, "/\\Atrue\\z/", "1"), "/\\A[^1].*\\z/", "0") * var.count}" | |
depends_on = ["aws_eip.instance"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jc-asdf: Hah! I almost did something like that too. The reason I didn't was that I didn't want to have to define that truefalse map in every module that used my hacky conditional logic, even though I think your approach is a little more readable. :)