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

Fix ALB listener rule update regression #11364

Merged
merged 2 commits into from
Dec 19, 2019
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the first issue GH-11323

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