Skip to content

Commit

Permalink
resource/aws_lb_listener_rule: Fix ALB listener rule update regression (
Browse files Browse the repository at this point in the history
#11364)

* Add some update tests. Issue #11323

New condition rule logic breaks when one a condition is present but
*not* being updated. Includes single condition when the action is being
modified. User is presented with:
Error: Only one of field, host_header, http_header,
http_request_method, path_pattern, query_string or source_ip can be set
in a condition block

* Handle rule updates when Condition not modified

Fixes #11323
Fixes #11362

Output from acceptance testing:

```
--- PASS: TestAccAWSLBListenerRule_conditionHttpHeader_invalid (3.89s)
--- PASS: TestAccAWSLBListenerRule_multipleConditionThrowsError (4.41s)
--- PASS: TestAccAWSLBListenerRule_conditionAttributesCount (28.37s)
--- PASS: TestAccAWSLBListenerRule_fixedResponse (175.92s)
--- PASS: TestAccAWSLBListenerRule_basic (180.33s)
--- PASS: TestAccAWSLBListenerRule_conditionHttpHeader (180.49s)
--- PASS: TestAccAWSLBListenerRule_conditionHttpRequestMethod (185.53s)
--- PASS: TestAccAWSLBListenerRule_conditionHostHeader (187.50s)
--- PASS: TestAccAWSLBListenerRule_cognito (190.30s)
--- PASS: TestAccAWSLBListenerRule_updateRulePriority (196.64s)
--- PASS: TestAccAWSLBListenerRule_conditionPathPattern_deprecated (202.36s)
--- PASS: TestAccAWSLBListenerRule_conditionPathPattern (209.18s)
--- PASS: TestAccAWSLBListenerRule_Action_Order (210.40s)
--- PASS: TestAccAWSLBListenerRule_conditionHostHeader_deprecated (215.83s)
--- PASS: TestAccAWSLBListenerRule_updateFixedResponse (221.31s)
--- PASS: TestAccAWSLBListenerRule_redirect (225.96s)
--- PASS: TestAccAWSLBListenerRule_oidc (226.93s)
--- PASS: TestAccAWSLBListenerRule_conditionQueryString (208.73s)
--- PASS: TestAccAWSLBListenerRule_conditionUpdatePathPattern_deprecated (240.20s)
--- PASS: TestAccAWSLBListenerRule_changeListenerRuleArnForcesNew (253.40s)
--- PASS: TestAccAWSLBListenerRuleBackwardsCompatibility (260.08s)
--- PASS: TestAccAWSLBListenerRule_Action_Order_Recreates (261.67s)
--- PASS: TestAccAWSLBListenerRule_priority (280.50s)
--- PASS: TestAccAWSLBListenerRule_conditionUpdateMultiple (177.25s)
--- PASS: TestAccAWSLBListenerRule_conditionMultiple (190.69s)
--- PASS: TestAccAWSLBListenerRule_conditionUpdateMixed (198.27s)
--- PASS: TestAccAWSLBListenerRule_conditionSourceIp (208.93s)
```
  • Loading branch information
dpiddockcmp authored and bflad committed Dec 19, 2019
1 parent b215493 commit 5dc0549
Show file tree
Hide file tree
Showing 2 changed files with 350 additions and 13 deletions.
30 changes: 23 additions & 7 deletions aws/resource_aws_lb_listener_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,14 +1264,30 @@ func lbListenerRuleConditions(conditions []interface{}) ([]*elbv2.RuleCondition,
}

// Deprecated backwards compatibility
if cmField, ok := conditionMap["field"].(string); ok && cmField != "" {
field = cmField
attrs += 1
values := conditionMap["values"].([]interface{})
if len(values) == 0 {
return nil, errors.New("Both field and values must be set in a condition block")
// This code is also hit during an update when the condition has not been modified. Issues: GH-11232 and GH-11362
if cmField, ok := conditionMap["field"].(string); ok && (cmField == "host-header" || cmField == "path-pattern") {
// When the condition is not being updated Terraform feeds in the existing state which has host header and
// path pattern set in both locations with identical values.
if field == cmField {
values := schema.NewSet(schema.HashString, conditionMap["values"].([]interface{}))
var values2 *schema.Set
if cmField == "host-header" {
values2 = conditionMap["host_header"].([]interface{})[0].(map[string]interface{})["values"].(*schema.Set)
} else {
values2 = conditionMap["path_pattern"].([]interface{})[0].(map[string]interface{})["values"].(*schema.Set)
}
if !values2.Equal(values) {
attrs += 1
}
} else {
field = cmField
attrs += 1
values := conditionMap["values"].([]interface{})
if len(values) == 0 {
return nil, errors.New("Both field and values must be set in a condition block")
}
elbConditions[i].Values = expandStringList(values)
}
elbConditions[i].Values = expandStringList(values)
}

// FIXME Rework this and use ConflictsWith when it finally works with collections:
Expand Down
Loading

0 comments on commit 5dc0549

Please sign in to comment.