Skip to content

Commit

Permalink
Merge pull request hashicorp#37887 from hashicorp/s-fixes
Browse files Browse the repository at this point in the history
Fix sweepers
  • Loading branch information
ewbankkit authored Jun 7, 2024
2 parents 240891a + 1871b30 commit ea7ba2b
Show file tree
Hide file tree
Showing 37 changed files with 790 additions and 729 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.55.0
github.com/aws/aws-sdk-go-v2/service/s3control v1.44.12
github.com/aws/aws-sdk-go-v2/service/scheduler v1.8.9
github.com/aws/aws-sdk-go-v2/service/schemas v1.24.9
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.29.2
github.com/aws/aws-sdk-go-v2/service/securityhub v1.49.1
github.com/aws/aws-sdk-go-v2/service/securitylake v1.13.8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ github.com/aws/aws-sdk-go-v2/service/s3control v1.44.12 h1:6F6JIv06AIJR7p+w9xjVY
github.com/aws/aws-sdk-go-v2/service/s3control v1.44.12/go.mod h1:vWJVDhTPJgkpHRjz/MMMVvqoAupZ1W9emLj5cfnkPzs=
github.com/aws/aws-sdk-go-v2/service/scheduler v1.8.9 h1:NH6WgOHc0dQlnKWUqVxHsfNC/ZVce94GSSMLBYBb5Rg=
github.com/aws/aws-sdk-go-v2/service/scheduler v1.8.9/go.mod h1:VHoM5NP6kQnC4az6zU5ES8quC+ze1RGyvLtPbRk23TI=
github.com/aws/aws-sdk-go-v2/service/schemas v1.24.9 h1:VbwQv2AcQib1nfsO4AE94fFSFjQ0+r8urRtph9QbSAs=
github.com/aws/aws-sdk-go-v2/service/schemas v1.24.9/go.mod h1:TKliQctpyxkDZLpLcSB/xwQTZ1FAlFh/iu7QdcQosHk=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.29.2 h1:vnONgeMo5TuAtGjVNjieDyaI6tzMDNm0TuBgkKzqkX4=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.29.2/go.mod h1:OR529kEc7Ty9nsqvMuDBBHq5AZVih/MYd5/G9TcL5bQ=
github.com/aws/aws-sdk-go-v2/service/securityhub v1.49.1 h1:Cvdok+6nG7oFCdi34QTfdy6OgFuNwOzR6sbqmTT3Kpg=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/service/cur/service_package.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions internal/service/devicefarm/device_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
awstypes "github.com/aws/aws-sdk-go-v2/service/devicefarm/types"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
Expand All @@ -28,7 +29,7 @@ import (

// @SDKResource("aws_devicefarm_device_pool", name="Device Pool")
// @Tags(identifierAttribute="arn")
func ResourceDevicePool() *schema.Resource {
func resourceDevicePool() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceDevicePoolCreate,
ReadWithoutTimeout: resourceDevicePoolRead,
Expand Down Expand Up @@ -134,7 +135,7 @@ func resourceDevicePoolRead(ctx context.Context, d *schema.ResourceData, meta in
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DeviceFarmClient(ctx)

devicePool, err := FindDevicePoolByARN(ctx, conn, d.Id())
devicePool, err := findDevicePoolByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] DeviceFarm Device Pool (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -225,6 +226,30 @@ func resourceDevicePoolDelete(ctx context.Context, d *schema.ResourceData, meta
return diags
}

func findDevicePoolByARN(ctx context.Context, conn *devicefarm.Client, arn string) (*awstypes.DevicePool, error) {
input := &devicefarm.GetDevicePoolInput{
Arn: aws.String(arn),
}
output, err := conn.GetDevicePool(ctx, input)

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

if err != nil {
return nil, err
}

if output == nil || output.DevicePool == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.DevicePool, nil
}

func expandDevicePoolRules(s *schema.Set) []awstypes.Rule {
rules := make([]awstypes.Rule, 0)

Expand Down
21 changes: 21 additions & 0 deletions internal/service/devicefarm/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package devicefarm

// Exports for use in tests only.
var (
ResourceDevicePool = resourceDevicePool
ResourceInstanceProfile = resourceInstanceProfile
ResourceNetworkProfile = resourceNetworkProfile
ResourceProject = resourceProject
ResourceTestGridProject = resourceTestGridProject
ResourceUpload = resourceUpload

FindDevicePoolByARN = findDevicePoolByARN
FindInstanceProfileByARN = findInstanceProfileByARN
FindNetworkProfileByARN = findNetworkProfileByARN
FindProjectByARN = findProjectByARN
FindTestGridProjectByARN = findTestGridProjectByARN
FindUploadByARN = findUploadByARN
)
159 changes: 0 additions & 159 deletions internal/service/devicefarm/find.go

This file was deleted.

29 changes: 27 additions & 2 deletions internal/service/devicefarm/instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/devicefarm"
awstypes "github.com/aws/aws-sdk-go-v2/service/devicefarm/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
Expand All @@ -25,7 +26,7 @@ import (

// @SDKResource("aws_devicefarm_instance_profile", name="Instance Profile")
// @Tags(identifierAttribute="arn")
func ResourceInstanceProfile() *schema.Resource {
func resourceInstanceProfile() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceInstanceProfileCreate,
ReadWithoutTimeout: resourceInstanceProfileRead,
Expand Down Expand Up @@ -116,7 +117,7 @@ func resourceInstanceProfileRead(ctx context.Context, d *schema.ResourceData, me
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DeviceFarmClient(ctx)

instanceProf, err := FindInstanceProfileByARN(ctx, conn, d.Id())
instanceProf, err := findInstanceProfileByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] DeviceFarm Instance Profile (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -197,3 +198,27 @@ func resourceInstanceProfileDelete(ctx context.Context, d *schema.ResourceData,

return diags
}

func findInstanceProfileByARN(ctx context.Context, conn *devicefarm.Client, arn string) (*awstypes.InstanceProfile, error) {
input := &devicefarm.GetInstanceProfileInput{
Arn: aws.String(arn),
}
output, err := conn.GetInstanceProfile(ctx, input)

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

if err != nil {
return nil, err
}

if output == nil || output.InstanceProfile == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.InstanceProfile, nil
}
Loading

0 comments on commit ea7ba2b

Please sign in to comment.