Skip to content

Commit

Permalink
Merge pull request #41739 from hashicorp/f-xray-resource-policy-sweeper
Browse files Browse the repository at this point in the history
Add sweeper for xray/resource_policy
  • Loading branch information
nam054 authored Mar 7, 2025
2 parents 384941c + 30eadb6 commit f6e4974
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/service/xray/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
"github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2"
"github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
"github.com/hashicorp/terraform-provider-aws/names"
)

func RegisterSweepers() {
awsv2.Register("aws_xray_group", sweepGroups)

awsv2.Register("aws_xray_sampling_rule", sweepSamplingRules)

awsv2.Register("aws_xray_resource_policy", sweepResourcePolicy)
}

func sweepGroups(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
Expand Down Expand Up @@ -82,3 +85,26 @@ func sweepSamplingRules(ctx context.Context, client *conns.AWSClient) ([]sweep.S

return sweepResources, nil
}

func sweepResourcePolicy(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
conn := client.XRayClient(ctx)
input := xray.ListResourcePoliciesInput{}

sweepResources := make([]sweep.Sweepable, 0)

pages := xray.NewListResourcePoliciesPaginator(conn, &input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)
if err != nil {
return nil, err
}

for _, v := range page.ResourcePolicies {
name := aws.ToString(v.PolicyName)

sweepResources = append(sweepResources, framework.NewSweepResource(newResourceResourcePolicy, client, framework.NewAttribute("policy_name", name)))
}
}

return sweepResources, nil
}

0 comments on commit f6e4974

Please sign in to comment.