[Bug]: Computed Security Groups for aws_lb trigger a replacement when load_balancer_type == "network" #33813
Labels
bug
Addresses a defect in current functionality.
service/elbv2
Issues and PRs that pertain to the elbv2 service.
Terraform Core Version
1.5.7
AWS Provider Version
5.20.0
Affected Resource(s)
Expected Behavior
Background
Per the AWS docs (links have been provided in the references section)
You can associate security groups with a Network Load Balancer when you create it. If you create a Network Load Balancer without associating any security groups, you can't associate them with the load balancer later on. We recommend that you associate a security group with your load balancer when you create it.
After you create a Network Load Balancer with associated security groups, you can change the security groups associated with the load balancer at any time.
Steps and Expected Behavior
main.tf
I create a security group, and an NLB (with newly created security group attached to it)Actual Behavior
When I run
terraform plan
I see that terraform is trying to create a new NLB, instead of updating in placesecurity_groups
field is "computed", i.e. the values are not known at plan time, but will become available at some point during the apply operationsRelevant Error/Panic Output Snippet
Terraform Configuration Files
Steps to Reproduce
terraform apply -auto-approve
terraform plan -var num_sgs=2
In the plan output you'll see that the NLB is being replaced, even though updating security groups can be done in-place.
Debug Output
No response
Panic Output
No response
Important Factoids
Looking around in the code the source of the issues appears to be
diff.GetChange("security_groups")
. When returning a Set object where the values isComputed
, the default behavior of the terraform provider is to return an empty set. We could optimize this by also callingdiff.NewValueKnown("security_groups.#")
to determine if the value is computed.References
AWS Reference Docs
Relevant Terraform Provider Links
aws_lb
resource to cover edge cases with network load balancer security groups. #32987Would you like to implement a fix?
Yes
The text was updated successfully, but these errors were encountered: