Skip to content

Conversation

zahorniak
Copy link

Description

Fixes incorrect VPC selection introduced in #353

Motivation and Context

Discussions can be found here and here

Breaking Changes

No

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@zahorniak zahorniak changed the title fix: Incorrect VPC selection introduced in #353 fix: Incorrect VPC selection for Security group introduced in #353 Oct 2, 2025

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
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.

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
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?

@antonbabenko
Copy link
Member

This issue has been resolved in version 6.6.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants