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

elbv2: Fix attribute key not recognized #23972

Merged
merged 5 commits into from
Mar 31, 2022
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/23972.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lb: Fix attribute key not recognized issue preventing creation in ISO-B regions
```
31 changes: 30 additions & 1 deletion internal/service/elbv2/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,25 @@ func resourceLoadBalancerUpdate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] ALB Modify Load Balancer Attributes Request: %#v", input)
_, err := conn.ModifyLoadBalancerAttributes(input)

// Not all attributes are supported in all partitions (e.g., ISO)
var err error
for {
_, err = conn.ModifyLoadBalancerAttributes(input)
if err == nil {
break
}

re := regexp.MustCompile(`attribute key ('|")?([^'" ]+)('|")? is not recognized`)
if sm := re.FindStringSubmatch(err.Error()); len(sm) > 1 {
log.Printf("[WARN] failed to modify Load Balancer (%s), unsupported attribute (%s): %s", d.Id(), sm[2], err)
input.Attributes = removeAttribute(input.Attributes, sm[2])
continue
}

break
}

if err != nil {
return fmt.Errorf("failure configuring LB attributes: %w", err)
}
Expand Down Expand Up @@ -658,6 +676,17 @@ func resourceLoadBalancerDelete(d *schema.ResourceData, meta interface{}) error
return nil
}

func removeAttribute(attributes []*elbv2.LoadBalancerAttribute, key string) []*elbv2.LoadBalancerAttribute {
for i, a := range attributes {
if aws.StringValue(a.Key) == key {
return append(attributes[:i], attributes[i+1:]...)
}
}

log.Printf("[WARN] Unable to remove attribute %s from Load Balancer attributes: not found", key)
return attributes
}

// ALB automatically creates ENI(s) on creation
// but the cleanup is asynchronous and may take time
// which then blocks IGW, SG or VPC on deletion
Expand Down