Skip to content

Commit

Permalink
Removes new error types
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Apr 27, 2021
1 parent 2c1cd93 commit 1afb84f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 244 deletions.
16 changes: 10 additions & 6 deletions aws/data_source_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package aws
import (
"errors"
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/ec2/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func dataSourceAwsSecurityGroup() *schema.Resource {
Expand Down Expand Up @@ -79,11 +80,14 @@ func dataSourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) er
}

sg, err := finder.SecurityGroup(conn, req)
if errors.Is(err, tfresource.ErrEmptyResult) {
return fmt.Errorf("no matching SecurityGroup found")
}
if errors.Is(err, tfresource.ErrTooManyResults) {
return fmt.Errorf("multiple Security Groups matched; use additional constraints to reduce matches to a single Security Group")
var nfe *resource.NotFoundError
if errors.As(err, &nfe) {
if nfe.Message == "empty result" {
return fmt.Errorf("no matching SecurityGroup found")
}
if strings.HasPrefix(nfe.Message, "too many results:") {
return fmt.Errorf("multiple Security Groups matched; use additional constraints to reduce matches to a single Security Group")
}
}
if err != nil {
return err
Expand Down
11 changes: 8 additions & 3 deletions aws/internal/service/ec2/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
tfnet "github.com/terraform-providers/terraform-provider-aws/aws/internal/net"
tfec2 "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/ec2"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

// CarrierGatewayByID returns the carrier gateway corresponding to the specified identifier.
Expand Down Expand Up @@ -363,11 +362,17 @@ func SecurityGroup(conn *ec2.EC2, input *ec2.DescribeSecurityGroupsInput) (*ec2.
}

if result == nil || len(result.SecurityGroups) == 0 || result.SecurityGroups[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
return nil, &resource.NotFoundError{
Message: "empty result",
LastRequest: input,
}
}

if len(result.SecurityGroups) > 1 {
return nil, tfresource.NewTooManyResultsError(len(result.SecurityGroups), input)
return nil, &resource.NotFoundError{
Message: fmt.Sprintf("too many results: wanted 1, got %d", len(result.SecurityGroups)),
LastRequest: input,
}
}

return result.SecurityGroups[0], nil
Expand Down
79 changes: 0 additions & 79 deletions aws/internal/tfresource/finder_errors.go

This file was deleted.

156 changes: 0 additions & 156 deletions aws/internal/tfresource/finder_errors_test.go

This file was deleted.

0 comments on commit 1afb84f

Please sign in to comment.