title: terraform conditional resource
body: <p>I have the following and I want to know what I am doing wrong, as I am sure I shouldn't have to double my code just because of a condition.</p>
  
  <p>So I want to do:</p>
  
  <pre><code>variable "https" { value = true }
  
  resource "aws_security_group" "http_instance_sg" {
    count       = "${var.https ? 0 : 1}"
  
    ......
  
  }
  resource "aws_security_group" "https_instance_sg" {
    count       = "${var.https ? 1 : 0}"
  
    ......
  
  }
  
  resource "aws_elb" "fe_elb" {
    security_groups = ["${var.https ? aws_aws_security_group.https_instance_sg.id : aws_aws_security_group.http_instance_sg.id}"]
     .....
  }
  </code></pre>
  
  <p>But when I do this terraform complains that <code>http_instance_sg</code> cant be found, which I get it hasn't be built, but surely I dont have to double up on all the code and have:</p>
  
  <pre><code> resource "aws_elb" "http_fe_elb" {
      count = "${var.https ? 0 : 1}"
      security_groups = ["${aws_aws_security_group.http_instance_sg.id}"]
     .....
    }
  
   resource "aws_elb" "https_fe_elb" {
      count = "${var.https ? 1 : 0}"
      security_groups = ["${aws_aws_security_group.https_instance_sg.id}"]
     .....
    }
  </code></pre>