Skip to content

Commit a7a2f18

Browse files
committed
fix: Addresses persistent diff with manage_default_network_acl
As noted in the [terraform docs][0], subnets using the default network acl will generate a persistent diff if they are not specified to the aws_default_network_acl resource. This module was handling subnets created by the module, but of course is not aware of subnets created externally to the module. The docs suggest using lifecycle ignore_changes as an option to avoid the persistence diff, which is the approach implemented in this patch. Fixes #736 [0]: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_network_acl#managing-subnets-in-a-default-network-acl
1 parent 6f89db5 commit a7a2f18

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

main.tf

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -587,28 +587,9 @@ resource "aws_default_network_acl" "this" {
587587

588588
default_network_acl_id = aws_vpc.this[0].default_network_acl_id
589589

590-
# The value of subnet_ids should be any subnet IDs that are not set as subnet_ids
591-
# for any of the non-default network ACLs
592-
subnet_ids = setsubtract(
593-
compact(flatten([
594-
aws_subnet.public[*].id,
595-
aws_subnet.private[*].id,
596-
aws_subnet.intra[*].id,
597-
aws_subnet.database[*].id,
598-
aws_subnet.redshift[*].id,
599-
aws_subnet.elasticache[*].id,
600-
aws_subnet.outpost[*].id,
601-
])),
602-
compact(flatten([
603-
aws_network_acl.public[*].subnet_ids,
604-
aws_network_acl.private[*].subnet_ids,
605-
aws_network_acl.intra[*].subnet_ids,
606-
aws_network_acl.database[*].subnet_ids,
607-
aws_network_acl.redshift[*].subnet_ids,
608-
aws_network_acl.elasticache[*].subnet_ids,
609-
aws_network_acl.outpost[*].subnet_ids,
610-
]))
611-
)
590+
# subnet_ids is using lifecycle ignore_changes, so it is not necessary to list
591+
# any explicitly. See https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/736.
592+
subnet_ids = null
612593

613594
dynamic "ingress" {
614595
for_each = var.default_network_acl_ingress
@@ -644,6 +625,10 @@ resource "aws_default_network_acl" "this" {
644625
var.tags,
645626
var.default_network_acl_tags,
646627
)
628+
629+
lifecycle {
630+
ignore_changes = [subnet_ids]
631+
}
647632
}
648633

649634
################################################################################

0 commit comments

Comments
 (0)