Skip to content

Commit 6253085

Browse files
authored
Merge pull request #45345 from hashicorp/b-resourceexplorer-sweep
sweeper/aws_resourceexplorer2_index: Excludes resources from other regions
2 parents bebe62b + f437568 commit 6253085

File tree

6 files changed

+25
-34
lines changed

6 files changed

+25
-34
lines changed

.changelog/45345.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_resourceexplorer2_index: Deprecates `id`. Use `arn` instead.
3+
```
4+
5+
```release-note:enhancement
6+
resource/aws_resourceexplorer2_view: Deprecates `id`. Use `arn` instead.
7+
```

internal/service/resourceexplorer2/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (r *indexResource) Schema(ctx context.Context, request resource.SchemaReque
5656
response.Schema = schema.Schema{
5757
Attributes: map[string]schema.Attribute{
5858
names.AttrARN: framework.ARNAttributeComputedOnly(),
59-
names.AttrID: framework.IDAttribute(),
59+
names.AttrID: framework.IDAttributeDeprecatedWithAlternate(path.Root(names.AttrARN)),
6060
names.AttrTags: tftags.TagsAttribute(),
6161
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
6262
names.AttrType: schema.StringAttribute{

internal/service/resourceexplorer2/index_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1616
tfresourceexplorer2 "github.com/hashicorp/terraform-provider-aws/internal/service/resourceexplorer2"
1717
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
18+
"github.com/hashicorp/terraform-provider-aws/internal/verify"
1819
"github.com/hashicorp/terraform-provider-aws/names"
1920
)
2021

@@ -35,7 +36,7 @@ func testAccIndex_basic(t *testing.T) {
3536
Config: testAccIndexConfig_basic,
3637
Check: resource.ComposeTestCheckFunc(
3738
testAccCheckIndexExists(ctx, resourceName),
38-
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "resource-explorer-2", regexache.MustCompile(`index/.+$`)),
39+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "resource-explorer-2", regexache.MustCompile(`index/`+verify.UUIDRegexPattern+`$`)),
3940
resource.TestCheckResourceAttr(resourceName, names.AttrType, "LOCAL"),
4041
),
4142
},

internal/service/resourceexplorer2/sweep.go

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,34 @@
44
package resourceexplorer2
55

66
import (
7-
"fmt"
8-
"log"
7+
"context"
98

109
"github.com/aws/aws-sdk-go-v2/aws"
1110
"github.com/aws/aws-sdk-go-v2/service/resourceexplorer2"
12-
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1312
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
1413
"github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2"
1514
"github.com/hashicorp/terraform-provider-aws/internal/sweep/framework"
1615
"github.com/hashicorp/terraform-provider-aws/names"
1716
)
1817

1918
func RegisterSweepers() {
20-
resource.AddTestSweepers("aws_resourceexplorer2_index", &resource.Sweeper{
21-
Name: "aws_resourceexplorer2_index",
22-
F: sweepIndexes,
23-
})
19+
awsv2.Register("aws_resourceexplorer2_index", sweepIndexes)
2420
}
2521

26-
func sweepIndexes(region string) error {
27-
ctx := sweep.Context(region)
28-
client, err := sweep.SharedRegionalSweepClient(ctx, region)
29-
if err != nil {
30-
return fmt.Errorf("getting client: %w", err)
31-
}
22+
func sweepIndexes(ctx context.Context, client *conns.AWSClient) ([]sweep.Sweepable, error) {
3223
conn := client.ResourceExplorer2Client(ctx)
33-
input := &resourceexplorer2.ListIndexesInput{}
34-
sweepResources := make([]sweep.Sweepable, 0)
3524

36-
pages := resourceexplorer2.NewListIndexesPaginator(conn, input)
25+
var sweepResources []sweep.Sweepable
26+
27+
input := resourceexplorer2.ListIndexesInput{
28+
Regions: []string{client.Region(ctx)},
29+
}
30+
pages := resourceexplorer2.NewListIndexesPaginator(conn, &input)
3731
for pages.HasMorePages() {
3832
page, err := pages.NextPage(ctx)
39-
40-
if awsv2.SkipSweepError(err) {
41-
log.Printf("[WARN] Skipping Resource Explorer Index sweep for %s: %s", region, err)
42-
return nil
43-
}
44-
4533
if err != nil {
46-
return fmt.Errorf("error listing Resource Explorer Indexes (%s): %w", region, err)
34+
return nil, err
4735
}
4836

4937
for _, v := range page.Indexes {
@@ -53,11 +41,5 @@ func sweepIndexes(region string) error {
5341
}
5442
}
5543

56-
err = sweep.SweepOrchestrator(ctx, sweepResources)
57-
58-
if err != nil {
59-
return fmt.Errorf("error sweeping Resource Explorer Indexes (%s): %w", region, err)
60-
}
61-
62-
return nil
44+
return sweepResources, nil
6345
}

internal/service/resourceexplorer2/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (r *viewResource) Schema(ctx context.Context, request resource.SchemaReques
6565
Computed: true,
6666
Default: booldefault.StaticBool(false),
6767
},
68-
names.AttrID: framework.IDAttribute(),
68+
names.AttrID: framework.IDAttributeDeprecatedWithAlternate(path.Root(names.AttrARN)),
6969
names.AttrName: schema.StringAttribute{
7070
Required: true,
7171
PlanModifiers: []planmodifier.String{

internal/service/resourceexplorer2/view_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1818
tfresourceexplorer2 "github.com/hashicorp/terraform-provider-aws/internal/service/resourceexplorer2"
1919
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
20+
"github.com/hashicorp/terraform-provider-aws/internal/verify"
2021
"github.com/hashicorp/terraform-provider-aws/names"
2122
)
2223

@@ -39,7 +40,7 @@ func testAccView_basic(t *testing.T) {
3940
Config: testAccViewConfig_basic(rName),
4041
Check: resource.ComposeAggregateTestCheckFunc(
4142
testAccCheckViewExists(ctx, resourceName, &v),
42-
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "resource-explorer-2", regexache.MustCompile(`view/.+$`)),
43+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "resource-explorer-2", regexache.MustCompile(`view/`+rName+`/`+verify.UUIDRegexPattern+`$`)),
4344
resource.TestCheckResourceAttr(resourceName, "default_view", acctest.CtFalse),
4445
resource.TestCheckResourceAttr(resourceName, "filters.#", "0"),
4546
resource.TestCheckResourceAttr(resourceName, "included_property.#", "0"),

0 commit comments

Comments
 (0)