Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1868,22 +1868,22 @@ locals {
}

data "aws_subnet" "this" {
count = local.create_security_group ? 1 : 0
count = local.create_security_group && length(var.subnet_ids) > 0 ? 1 : 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work when passing computed values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very true, should we update the default variable declaration to require the subnet_ids to be provided then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats now how we manage variables - we provide default values so that we can disable all resource creation by simply setting create = true. Terraform doesn't allow us to simply disable resource creation and ignore required values (they aren't required if the resource is not going to be created/executed), which results in us providing a value, any value, to ensure we can disable without forcing users to provide values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fair and sounds more like the user didn't properly enter the parameters they needed with the configuration they were attempting to construct. Closing this PR now


region = var.region

id = element(var.subnet_ids, 0)
}

resource "aws_security_group" "this" {
count = local.create_security_group ? 1 : 0
count = local.create_security_group && length(var.subnet_ids) > 0 ? 1 : 0

region = var.region

name = var.security_group_use_name_prefix ? null : local.security_group_name
name_prefix = var.security_group_use_name_prefix ? "${local.security_group_name}-" : null
description = var.security_group_description
vpc_id = var.vpc_id != null ? var.vpc_id : data.aws_subnet.this[0].vpc_id
vpc_id = var.vpc_id != null ? var.vpc_id : one(data.aws_subnet.this[*].vpc_id)

tags = merge(
var.tags,
Expand Down
Loading