Last active
          May 4, 2018 18:40 
        
      - 
      
- 
        Save dalethestirling/466475bd09bee98f80674b1f7c785751 to your computer and use it in GitHub Desktop. 
    Feature toggles in Terraform
  
        
  
    
      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
    
  
  
    
  | # 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)" | |
| } | 
  
    
      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
    
  
  
    
  | 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 }" | |
| } | 
  
    
      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
    
  
  
    
  | 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