Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module "service" {
assign_public_ip = each.value.assign_public_ip
security_group_ids = each.value.security_group_ids
subnet_ids = each.value.subnet_ids
vpc_id = each.value.vpc_id
ordered_placement_strategy = each.value.ordered_placement_strategy
placement_constraints = each.value.placement_constraints
platform_version = each.value.platform_version
Expand Down
4 changes: 2 additions & 2 deletions modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ locals {
}

data "aws_subnet" "this" {
count = local.create_security_group && var.vpc_id != null ? 1 : 0
count = local.create_security_group ? 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 is incorrect - it should be

Suggested change
count = local.create_security_group ? 1 : 0
count = local.create_security_group && var.vpc_id == null ? 1 : 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bryantbiggs, with the suggested code, the Terraform plan is failing on example/complete. I tried this as well, but it didn't work, and I decided not to investigate further why it's not working.

│ Error: Invalid count argument
│ 
│   on ../../modules/service/main.tf line 1641, in data "aws_subnet" "this":
│ 1641:   count = local.create_security_group && var.vpc_id == null ? 1 : 0
│ 
│ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many
│ instances will be created. To work around this, use the -target argument to first apply only the resources that the count
│ depends on.


region = var.region

Expand All @@ -1653,7 +1653,7 @@ resource "aws_security_group" "this" {
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 = try(data.aws_subnet.this[0].vpc_id, var.vpc_id)
vpc_id = coalesce(var.vpc_id, data.aws_subnet.this[0].vpc_id)
Copy link
Member

Choose a reason for hiding this comment

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

this is incorrect - it has the potential to fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bryantbiggs, do you have any ideas on how to prevent this?


tags = merge(
var.tags,
Expand Down
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ variable "services" {
assign_public_ip = optional(bool)
security_group_ids = optional(list(string))
subnet_ids = optional(list(string))
vpc_id = optional(string)
ordered_placement_strategy = optional(map(object({
field = optional(string)
type = string
Expand Down
2 changes: 1 addition & 1 deletion wrappers/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ module "wrapper" {
task_exec_iam_statements = try(each.value.task_exec_iam_statements, var.defaults.task_exec_iam_statements, null)
task_exec_secret_arns = try(each.value.task_exec_secret_arns, var.defaults.task_exec_secret_arns, [])
task_exec_ssm_param_arns = try(each.value.task_exec_ssm_param_arns, var.defaults.task_exec_ssm_param_arns, [])
task_tags = try(each.value.task_tags, var.defaults.task_tags, {})
tasks_iam_role_arn = try(each.value.tasks_iam_role_arn, var.defaults.tasks_iam_role_arn, null)
tasks_iam_role_description = try(each.value.tasks_iam_role_description, var.defaults.tasks_iam_role_description, null)
tasks_iam_role_name = try(each.value.tasks_iam_role_name, var.defaults.tasks_iam_role_name, null)
Expand All @@ -133,6 +132,7 @@ module "wrapper" {
tasks_iam_role_statements = try(each.value.tasks_iam_role_statements, var.defaults.tasks_iam_role_statements, null)
tasks_iam_role_tags = try(each.value.tasks_iam_role_tags, var.defaults.tasks_iam_role_tags, {})
tasks_iam_role_use_name_prefix = try(each.value.tasks_iam_role_use_name_prefix, var.defaults.tasks_iam_role_use_name_prefix, true)
task_tags = try(each.value.task_tags, var.defaults.task_tags, {})
timeouts = try(each.value.timeouts, var.defaults.timeouts, null)
track_latest = try(each.value.track_latest, var.defaults.track_latest, true)
triggers = try(each.value.triggers, var.defaults.triggers, null)
Expand Down