Skip to content

Commit

Permalink
Merge main into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Oct 24, 2024
2 parents 8215189 + 2937219 commit aae6b27
Show file tree
Hide file tree
Showing 28 changed files with 2,656 additions and 115 deletions.
3 changes: 3 additions & 0 deletions .changelog/39865.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_lb_listener_rule
```
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
## 5.74.0 (Unreleased)

FEATURES:

* **New Data Source:** `aws_lb_listener_rule` ([#39865](https://github.com/hashicorp/terraform-provider-aws/issues/39865))

ENHANCEMENTS:

* resource/aws_codedeploy_deployment_group: Add `termination_hook_enabled` argument ([#35482](https://github.com/hashicorp/terraform-provider-aws/issues/35482))

## 5.73.0 (October 24, 2024)

FEATURES:
Expand Down
9 changes: 9 additions & 0 deletions internal/provider/fwprovider/intercept.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ func (w *wrappedDataSource) Configure(ctx context.Context, request datasource.Co
w.inner.Configure(ctx, request, response)
}

func (w *wrappedDataSource) ConfigValidators(ctx context.Context) []datasource.ConfigValidator {
if v, ok := w.inner.(datasource.DataSourceWithConfigValidators); ok {
ctx = w.bootstrapContext(ctx, w.meta)
return v.ConfigValidators(ctx)
}

return nil
}

// tagsDataSourceInterceptor implements transparent tagging for data sources.
type tagsDataSourceInterceptor struct {
tags *types.ServicePackageResourceTags
Expand Down
1 change: 1 addition & 0 deletions internal/provider/fwprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ func (p *fwprovider) DataSources(ctx context.Context) []func() datasource.DataSo
if meta != nil {
ctx = tftags.NewContext(ctx, meta.DefaultTagsConfig(ctx), meta.IgnoreTagsConfig(ctx))
ctx = meta.RegisterLogger(ctx)
ctx = flex.RegisterLogger(ctx)
}

return ctx
Expand Down
1 change: 0 additions & 1 deletion internal/service/elbv2/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeListenerCertificates -InputPaginator=Marker -OutputPaginator=NextMarker -- list_listener_certificates_pages_gen.go
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeRules -InputPaginator=Marker -OutputPaginator=NextMarker -- list_rules_pages_gen.go
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=DescribeTags -ListTagsInIDElem=ResourceArns -ListTagsInIDNeedValueSlice=yes -ListTagsOutTagsElem=TagDescriptions[0].Tags -ServiceTagsSlice -TagOp=AddTags -TagInIDElem=ResourceArns -TagInIDNeedValueSlice=yes -UntagOp=RemoveTags -UpdateTags -CreateTags -KVTValues
//go:generate go run ../../generate/servicepackage/main.go
//go:generate go run ../../generate/tagstests/main.go
Expand Down
27 changes: 0 additions & 27 deletions internal/service/elbv2/list_rules_pages_gen.go

This file was deleted.

14 changes: 10 additions & 4 deletions internal/service/elbv2/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package elbv2

import (
"cmp"
"context"
"fmt"
"log"
"slices"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -572,9 +572,9 @@ func resourceListenerRead(ctx context.Context, d *schema.ResourceData, meta inte
if len(listener.Certificates) == 1 {
d.Set(names.AttrCertificateARN, listener.Certificates[0].CertificateArn)
}
sort.Slice(listener.DefaultActions, func(i, j int) bool {
return aws.ToInt32(listener.DefaultActions[i].Order) < aws.ToInt32(listener.DefaultActions[j].Order)
})

sortListenerActions(listener.DefaultActions)

if err := d.Set(names.AttrDefaultAction, flattenListenerActions(d, names.AttrDefaultAction, listener.DefaultActions)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting default_action: %s", err)
}
Expand Down Expand Up @@ -1689,3 +1689,9 @@ func diffSuppressMissingForward(attrName string) schema.SchemaDiffSuppressFunc {
return false
}
}

func sortListenerActions(actions []awstypes.Action) {
slices.SortFunc(actions, func(a, b awstypes.Action) int {
return cmp.Compare(aws.ToInt32(a.Order), aws.ToInt32(b.Order))
})
}
7 changes: 3 additions & 4 deletions internal/service/elbv2/listener_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package elbv2

import (
"context"
"sort"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -334,9 +333,9 @@ func dataSourceListenerRead(ctx context.Context, d *schema.ResourceData, meta in
if len(listener.Certificates) == 1 {
d.Set(names.AttrCertificateARN, listener.Certificates[0].CertificateArn)
}
sort.Slice(listener.DefaultActions, func(i, j int) bool {
return aws.ToInt32(listener.DefaultActions[i].Order) < aws.ToInt32(listener.DefaultActions[j].Order)
})

sortListenerActions(listener.DefaultActions)

if err := d.Set(names.AttrDefaultAction, flattenListenerActions(d, names.AttrDefaultAction, listener.DefaultActions)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting default_action: %s", err)
}
Expand Down
61 changes: 32 additions & 29 deletions internal/service/elbv2/listener_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"log"
"slices"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -47,7 +46,7 @@ const (

// @SDKResource("aws_alb_listener_rule", name="Listener Rule")
// @SDKResource("aws_lb_listener_rule", name="Listener Rule")
// @Tags(identifierAttribute="id")
// @Tags(identifierAttribute="arn")
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types;awstypes;awstypes.Rule")
// @Testing(importIgnore="action.0.forward")
func resourceListenerRule() *schema.Resource {
Expand Down Expand Up @@ -578,9 +577,8 @@ func resourceListenerRuleRead(ctx context.Context, d *schema.ResourceData, meta
}
}

sort.Slice(rule.Actions, func(i, j int) bool {
return aws.ToInt32(rule.Actions[i].Order) < aws.ToInt32(rule.Actions[j].Order)
})
sortListenerActions(rule.Actions)

if err := d.Set(names.AttrAction, flattenListenerActions(d, names.AttrAction, rule.Actions)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting action: %s", err)
}
Expand Down Expand Up @@ -765,29 +763,24 @@ func findListenerRule(ctx context.Context, conn *elasticloadbalancingv2.Client,
func findListenerRules(ctx context.Context, conn *elasticloadbalancingv2.Client, input *elasticloadbalancingv2.DescribeRulesInput, filter tfslices.Predicate[*awstypes.Rule]) ([]awstypes.Rule, error) {
var output []awstypes.Rule

err := describeRulesPages(ctx, conn, input, func(page *elasticloadbalancingv2.DescribeRulesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
paginator := elasticloadbalancingv2.NewDescribeRulesPaginator(conn, input)
for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)
if errs.IsA[*awstypes.RuleNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}
if err != nil {
return nil, err
}

for _, v := range page.Rules {
if filter(&v) {
output = append(output, v)
}
}

return !lastPage
})

if errs.IsA[*awstypes.RuleNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

return output, nil
Expand All @@ -801,6 +794,16 @@ func findListenerRuleByARN(ctx context.Context, conn *elasticloadbalancingv2.Cli
return findListenerRule(ctx, conn, input, tfslices.PredicateTrue[*awstypes.Rule]())
}

func findListenerRuleByListenerAndPriority(ctx context.Context, conn *elasticloadbalancingv2.Client, listenerARN, priority string) (*awstypes.Rule, error) {
input := &elasticloadbalancingv2.DescribeRulesInput{
ListenerArn: aws.String(listenerARN),
}

return findListenerRule(ctx, conn, input, func(v *awstypes.Rule) bool {
return aws.ToString(v.Priority) == priority
})
}

func highestListenerRulePriority(ctx context.Context, conn *elasticloadbalancingv2.Client, arn string) (int32, error) {
input := &elasticloadbalancingv2.DescribeRulesInput{
ListenerArn: aws.String(arn),
Expand Down Expand Up @@ -832,15 +835,15 @@ func validListenerRulePriority(v interface{}, k string) (ws []string, errors []e
return
}

// from arn:
// arn:aws:elasticloadbalancing:us-east-1:012345678912:listener-rule/app/name/0123456789abcdef/abcdef0123456789/456789abcedf1234
// select submatches:
// (arn:aws:elasticloadbalancing:us-east-1:012345678912:listener)-rule(/app/name/0123456789abcdef/abcdef0123456789)/456789abcedf1234
// concat to become:
// arn:aws:elasticloadbalancing:us-east-1:012345678912:listener/app/name/0123456789abcdef/abcdef0123456789
var lbListenerARNFromRuleARNRegexp = regexache.MustCompile(`^(arn:.+:listener)-rule(/.+)/[^/]+$`)

func listenerARNFromRuleARN(ruleARN string) string {
// from arn:
// arn:aws:elasticloadbalancing:us-east-1:012345678912:listener-rule/app/name/0123456789abcdef/abcdef0123456789/456789abcedf1234
// select submatches:
// (arn:aws:elasticloadbalancing:us-east-1:012345678912:listener)-rule(/app/name/0123456789abcdef/abcdef0123456789)/456789abcedf1234
// concat to become:
// arn:aws:elasticloadbalancing:us-east-1:012345678912:listener/app/name/0123456789abcdef/abcdef0123456789
var lbListenerARNFromRuleARNRegexp = regexache.MustCompile(`^(arn:.+:listener)-rule(/.+)/[^/]+$`)

if arnComponents := lbListenerARNFromRuleARNRegexp.FindStringSubmatch(ruleARN); len(arnComponents) > 1 {
return arnComponents[1] + arnComponents[2]
}
Expand Down
Loading

0 comments on commit aae6b27

Please sign in to comment.