From b818eca56d1b56b687031c23d813ac5fd575010d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 29 Jan 2025 08:00:29 -0500 Subject: [PATCH 1/6] r/aws_bedrockagent_knowledge_base: Add sweeper. --- internal/service/bedrockagent/sweep.go | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 internal/service/bedrockagent/sweep.go diff --git a/internal/service/bedrockagent/sweep.go b/internal/service/bedrockagent/sweep.go new file mode 100644 index 00000000000..29eba442a21 --- /dev/null +++ b/internal/service/bedrockagent/sweep.go @@ -0,0 +1,42 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package bedrockagent + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/bedrockagent" + "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_bedrockagent_knowledge_base", sweepKnowledgeBases) +} + +func sweepKnowledgeBases(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) { + input := &bedrockagent.ListKnowledgeBasesInput{} + conn := client.BedrockAgentClient(ctx) + sweepResources := make([]sweep.Sweepable, 0) + + pages := bedrockagent.NewListKnowledgeBasesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err + } + + for _, v := range page.KnowledgeBaseSummaries { + sweepResources = append(sweepResources, framework.NewSweepResource(newKnowledgeBaseResource, client, + framework.NewAttribute(names.AttrARN, aws.ToString(v.KnowledgeBaseId)))) + } + } + + return sweepResources, nil +} From 7311e1a29a77cf02df749d33c6250ae5349015fc Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 29 Jan 2025 08:01:59 -0500 Subject: [PATCH 2/6] Run 'make gen'. --- internal/sweep/register_gen_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/sweep/register_gen_test.go b/internal/sweep/register_gen_test.go index 5a3002111c4..80c1b7aee95 100644 --- a/internal/sweep/register_gen_test.go +++ b/internal/sweep/register_gen_test.go @@ -26,6 +26,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/service/backup" "github.com/hashicorp/terraform-provider-aws/internal/service/batch" "github.com/hashicorp/terraform-provider-aws/internal/service/bcmdataexports" + "github.com/hashicorp/terraform-provider-aws/internal/service/bedrockagent" "github.com/hashicorp/terraform-provider-aws/internal/service/budgets" "github.com/hashicorp/terraform-provider-aws/internal/service/chime" "github.com/hashicorp/terraform-provider-aws/internal/service/cleanrooms" @@ -196,6 +197,7 @@ func registerSweepers() { backup.RegisterSweepers() batch.RegisterSweepers() bcmdataexports.RegisterSweepers() + bedrockagent.RegisterSweepers() budgets.RegisterSweepers() chime.RegisterSweepers() cleanrooms.RegisterSweepers() From fd567177b5e2d0a5870fa0e65451adc4f7d50584 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 29 Jan 2025 08:07:48 -0500 Subject: [PATCH 3/6] r/aws_bedrockagent_data_source: Add sweeper. --- internal/service/bedrockagent/sweep.go | 27 ++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/internal/service/bedrockagent/sweep.go b/internal/service/bedrockagent/sweep.go index 29eba442a21..6b4fa537a3c 100644 --- a/internal/service/bedrockagent/sweep.go +++ b/internal/service/bedrockagent/sweep.go @@ -16,7 +16,30 @@ import ( ) func RegisterSweepers() { - awsv2.Register("aws_bedrockagent_knowledge_base", sweepKnowledgeBases) + awsv2.Register("aws_bedrockagent_data_source", sweepDataSources) + awsv2.Register("aws_bedrockagent_knowledge_base", sweepKnowledgeBases, "aws_bedrockagent_data_source") +} + +func sweepDataSources(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) { + input := &bedrockagent.ListDataSourcesInput{} + conn := client.BedrockAgentClient(ctx) + sweepResources := make([]sweep.Sweepable, 0) + + pages := bedrockagent.NewListDataSourcesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err + } + + for _, v := range page.DataSourceSummaries { + sweepResources = append(sweepResources, framework.NewSweepResource(newDataSourceResource, client, + framework.NewAttribute("data_source_id", aws.ToString(v.DataSourceId)), framework.NewAttribute("knowledge_base_id", aws.ToString(v.KnowledgeBaseId)))) + } + } + + return sweepResources, nil } func sweepKnowledgeBases(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) { @@ -34,7 +57,7 @@ func sweepKnowledgeBases(ctx context.Context, client *conns.AWSClient) ([]sweep. for _, v := range page.KnowledgeBaseSummaries { sweepResources = append(sweepResources, framework.NewSweepResource(newKnowledgeBaseResource, client, - framework.NewAttribute(names.AttrARN, aws.ToString(v.KnowledgeBaseId)))) + framework.NewAttribute(names.AttrID, aws.ToString(v.KnowledgeBaseId)))) } } From 62281912e3b3cb00b17fb017f0a1f15c27812efb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 29 Jan 2025 08:18:13 -0500 Subject: [PATCH 4/6] r/aws_bedrockagent_data_source: Fix sweeper. --- internal/service/bedrockagent/sweep.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/internal/service/bedrockagent/sweep.go b/internal/service/bedrockagent/sweep.go index 6b4fa537a3c..f09b9859629 100644 --- a/internal/service/bedrockagent/sweep.go +++ b/internal/service/bedrockagent/sweep.go @@ -21,11 +21,11 @@ func RegisterSweepers() { } func sweepDataSources(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) { - input := &bedrockagent.ListDataSourcesInput{} + input := &bedrockagent.ListKnowledgeBasesInput{} conn := client.BedrockAgentClient(ctx) sweepResources := make([]sweep.Sweepable, 0) - pages := bedrockagent.NewListDataSourcesPaginator(conn, input) + pages := bedrockagent.NewListKnowledgeBasesPaginator(conn, input) for pages.HasMorePages() { page, err := pages.NextPage(ctx) @@ -33,9 +33,24 @@ func sweepDataSources(ctx context.Context, client *conns.AWSClient) ([]sweep.Swe return nil, err } - for _, v := range page.DataSourceSummaries { - sweepResources = append(sweepResources, framework.NewSweepResource(newDataSourceResource, client, - framework.NewAttribute("data_source_id", aws.ToString(v.DataSourceId)), framework.NewAttribute("knowledge_base_id", aws.ToString(v.KnowledgeBaseId)))) + for _, v := range page.KnowledgeBaseSummaries { + input := &bedrockagent.ListDataSourcesInput{ + KnowledgeBaseId: v.KnowledgeBaseId, + } + + pages := bedrockagent.NewListDataSourcesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err + } + + for _, v := range page.DataSourceSummaries { + sweepResources = append(sweepResources, framework.NewSweepResource(newDataSourceResource, client, + framework.NewAttribute("data_source_id", aws.ToString(v.DataSourceId)), framework.NewAttribute("knowledge_base_id", aws.ToString(v.KnowledgeBaseId)))) + } + } } } From 596c1313ac9c0b7038653f0cbe18e9737d8c0f12 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 29 Jan 2025 08:21:37 -0500 Subject: [PATCH 5/6] r/aws_bedrockagent_agent: Add sweeper. --- internal/service/bedrockagent/sweep.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/service/bedrockagent/sweep.go b/internal/service/bedrockagent/sweep.go index f09b9859629..7734ec02792 100644 --- a/internal/service/bedrockagent/sweep.go +++ b/internal/service/bedrockagent/sweep.go @@ -16,10 +16,33 @@ import ( ) func RegisterSweepers() { + awsv2.Register("aws_bedrockagent_agent", sweepAgents) awsv2.Register("aws_bedrockagent_data_source", sweepDataSources) awsv2.Register("aws_bedrockagent_knowledge_base", sweepKnowledgeBases, "aws_bedrockagent_data_source") } +func sweepAgents(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) { + input := &bedrockagent.ListAgentsInput{} + conn := client.BedrockAgentClient(ctx) + sweepResources := make([]sweep.Sweepable, 0) + + pages := bedrockagent.NewListAgentsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err + } + + for _, v := range page.AgentSummaries { + sweepResources = append(sweepResources, framework.NewSweepResource(newAgentResource, client, + framework.NewAttribute("agent_id", aws.ToString(v.AgentId)), framework.NewAttribute("skip_resource_in_use_check", true))) + } + } + + return sweepResources, nil +} + func sweepDataSources(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) { input := &bedrockagent.ListKnowledgeBasesInput{} conn := client.BedrockAgentClient(ctx) From 1ef871833ed71a17a91ea14e5cbb7431ade07f43 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 29 Jan 2025 08:42:59 -0500 Subject: [PATCH 6/6] r/aws_bedrockagent_agent: Fix sweeper. --- internal/service/bedrockagent/agent.go | 2 +- internal/service/bedrockagent/sweep.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/bedrockagent/agent.go b/internal/service/bedrockagent/agent.go index e74f1b13047..e9c0a7e719a 100644 --- a/internal/service/bedrockagent/agent.go +++ b/internal/service/bedrockagent/agent.go @@ -389,7 +389,7 @@ func (r *agentResource) Delete(ctx context.Context, request resource.DeleteReque agentID := data.ID.ValueString() _, err := conn.DeleteAgent(ctx, &bedrockagent.DeleteAgentInput{ - AgentId: fwflex.StringFromFramework(ctx, data.AgentID), + AgentId: aws.String(agentID), SkipResourceInUseCheck: fwflex.BoolValueFromFramework(ctx, data.SkipResourceInUseCheck), }) diff --git a/internal/service/bedrockagent/sweep.go b/internal/service/bedrockagent/sweep.go index 7734ec02792..bd5cac5e1f0 100644 --- a/internal/service/bedrockagent/sweep.go +++ b/internal/service/bedrockagent/sweep.go @@ -18,7 +18,7 @@ import ( func RegisterSweepers() { awsv2.Register("aws_bedrockagent_agent", sweepAgents) awsv2.Register("aws_bedrockagent_data_source", sweepDataSources) - awsv2.Register("aws_bedrockagent_knowledge_base", sweepKnowledgeBases, "aws_bedrockagent_data_source") + awsv2.Register("aws_bedrockagent_knowledge_base", sweepKnowledgeBases, "aws_bedrockagent_agent", "aws_bedrockagent_data_source") } func sweepAgents(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) { @@ -36,7 +36,7 @@ func sweepAgents(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepabl for _, v := range page.AgentSummaries { sweepResources = append(sweepResources, framework.NewSweepResource(newAgentResource, client, - framework.NewAttribute("agent_id", aws.ToString(v.AgentId)), framework.NewAttribute("skip_resource_in_use_check", true))) + framework.NewAttribute(names.AttrID, aws.ToString(v.AgentId)), framework.NewAttribute("skip_resource_in_use_check", true))) } }