Skip to content

Instantly share code, notes, and snippets.

@dalethestirling
Last active May 4, 2018 18:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalethestirling/466475bd09bee98f80674b1f7c785751 to your computer and use it in GitHub Desktop.
Save dalethestirling/466475bd09bee98f80674b1f7c785751 to your computer and use it in GitHub Desktop.
Feature toggles in Terraform
# Terraform converts boolean values to 1 (true) and 0 (false)
# This passed into the count sets the count to 1 or zero effectivly creating or skipping the resource
variable "create_my_group" { default="true" }
variable "name_my_group" { default="my_group" }
variabble "vpc_my_group" { default="vpcid" }
resource "aws_security_group" "my_group" {
count = "${var.create_my_group}"
name = "${var.name_my_group}"
vpc_id = "${var.vpc_id)"
}
variable "toggle" { default="false" }
variable "true_val" { default="true_val" }
variable "false_val" { default="false_val" }
output "toggle_result" {
value = "${ var.toggle ? var.true_val : var.false_val }"
}
variable "toggle_efs" { default="true" }
variable "efs_target_qty" { default=3 }
data "aws_subnet" "data_tier" {
filter {
name = "tag:StorageClass"
values = ["data_storage"]
}
}
resource "aws_efs_file_system" "data_vol" {
count = "${ var.toggle_efs ? 1 : 0 }"
}
resource "aws_efs_mount_target" "data_vol_mount" {
count = "${ var.toggle_efs ? var.efs_target_qty : 0 }"
file_system_id = "${aws_efs_file_system.data_vol.id}"
subnet_id = "${element(data.aws_subnet.data_tier.*.id, count.index)}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment