Dynamic data block using feature flag?

Hello all!

I’d like to add a data block to find an aws security group using a feature flag/var, if the variable is false, then the security group does not get added. Currently I have something like this:

data "aws_security_group" "sggroup" {
  count = var.enable_sggroup ? 1 : 0
  tags = {
Usage = "sggroup"
  } 
}

Then based off of the above, I would use the concat function in the aws_lb resource block in order to add or not add the security group in question

resource "aws_lb" "loadbalancer" {
  name               = "lb-${var.name_prefix}"
  internal           = false
  load_balancer_type = "application"
  security_groups    = concat(["${var.lb_security_group}", "${data.aws_security_group.sggroup2.id}"], "${data.aws_security_groups.sggroups.ids}", ["${data.aws_security_group.sggroup.id}"])

Would anyone be able to let me know if I am on the right track?

Getting this error when running a plan

Because data.aws_security_group.sggroup has "count" set, its attributes must
be accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
    data.aws_security_group.sggroup[count.index]