Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updating security groups for NLBs doesn't trigger a replacement #33814

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
28 changes: 21 additions & 7 deletions internal/service/elbv2/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,15 +1048,29 @@ func customizeDiffNLB(_ context.Context, diff *schema.ResourceDiff, v interface{
}

// Get diff for security groups.
o, n = diff.GetChange("security_groups")
os, ns = o.(*schema.Set), n.(*schema.Set)

if (os.Len() == 0 && ns.Len() > 0) || (ns.Len() == 0 && os.Len() > 0) {
if err := diff.ForceNew("security_groups"); err != nil {
return err
sgCountKnown := diff.NewValueKnown("security_groups.#")
o, n = diff.GetChange("security_groups.#")
oi, ni := o.(int), n.(int)

// If the final values for the security_groups field is known, then we can compare the old and new security_group
// counts. If one value is zero and the other value is non-zero, then trigger a replacement
if sgCountKnown {
if (oi == 0 && ni > 0) || (ni == 0 && oi > 0) {
if err := diff.ForceNew("security_groups"); err != nil {
return err
}
}
// Here's where things get complicated. If the value is computed, then the final output could be zero or non-zero
// This code block is going to make the assumption that when the value is computed, it is the intent of the
// developer for that final computed value to be non-zero.
} else {
log.Println("[DEBUG] security_groups is a computed value, will assume the final is greater than 0")
if oi == 0 {
if err := diff.ForceNew("security_groups"); err != nil {
return err
}
}
}

return nil
}

Expand Down