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

Dont recreate listener rule after priority change #23768

Merged
Merged
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
3 changes: 3 additions & 0 deletions .changelog/23768.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_alb_listener_rule: Don't force recreate listener rule on priority change.
```
2 changes: 1 addition & 1 deletion internal/service/elbv2/listener_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ResourceListenerRule() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
ForceNew: false,
ValidateFunc: validListenerRulePriority,
},
"action": {
Expand Down
25 changes: 18 additions & 7 deletions internal/service/elbv2/listener_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func TestAccELBV2ListenerRule_updateFixedResponse(t *testing.T) {
}

func TestAccELBV2ListenerRule_updateRulePriority(t *testing.T) {
var rule elbv2.Rule
var before, after elbv2.Rule
lbName := fmt.Sprintf("testrule-basic-%s", sdkacctest.RandString(13))
targetGroupName := fmt.Sprintf("testtargetgroup-%s", sdkacctest.RandString(10))

Expand All @@ -450,14 +450,15 @@ func TestAccELBV2ListenerRule_updateRulePriority(t *testing.T) {
{
Config: testAccListenerRuleConfig_basic(lbName, targetGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckListenerRuleExists(resourceName, &rule),
testAccCheckListenerRuleExists(resourceName, &before),
resource.TestCheckResourceAttr(resourceName, "priority", "100"),
),
},
{
Config: testAccListenerRuleConfig_updateRulePriority(lbName, targetGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckListenerRuleExists(resourceName, &rule),
testAccCheckListenerRuleExists(resourceName, &after),
testAccCheckListenerRuleNotRecreated(t, &before, &after),
resource.TestCheckResourceAttr(resourceName, "priority", "101"),
),
},
Expand Down Expand Up @@ -1320,12 +1321,22 @@ func testAccCheckListenerRuleActionOrderDisappears(rule *elbv2.Rule, actionOrder
}
}

func testAccCheckListenerRuleRecreated(t *testing.T,
before, after *elbv2.Rule) resource.TestCheckFunc {
func testAccCheckListenerRuleNotRecreated(t *testing.T, before, after *elbv2.Rule) resource.TestCheckFunc {
return func(s *terraform.State) error {
if before, after := aws.StringValue(before.RuleArn), aws.StringValue(after.RuleArn); before != after {
t.Fatalf("ELBv2 Listener Rule (%s) was recreated: %s", before, after)
}

return nil
}
}

func testAccCheckListenerRuleRecreated(t *testing.T, before, after *elbv2.Rule) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *before.RuleArn == *after.RuleArn {
t.Fatalf("Expected change of Listener Rule ARNs, but both were %v", before.RuleArn)
if before, after := aws.StringValue(before.RuleArn), aws.StringValue(after.RuleArn); before == after {
t.Fatalf("ELBv2 Listener Rule (%s) was not recreated", before)
}

return nil
}
}
Expand Down