Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: Improve Error/Diag handling for nested resources (#1214)
Browse files Browse the repository at this point in the history

#### Summary

- Panic When No lambda:Get* permissions
- Don't return early if IoT:DescribeStream ends early


---
  • Loading branch information
bbernays committed Jul 13, 2022
1 parent e75f91b commit 9a55267
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var accessDeniedErrorStrings = map[string]struct{}{
"AccessDeniedException": {},
"InsufficientPrivilegesException": {},
"UnauthorizedOperation": {},
"Unauthorized": {},
}

func readSupportedServiceRegions() *SupportedServiceRegionsData {
Expand Down
9 changes: 6 additions & 3 deletions resources/services/iot/iot_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func IotStreams() *schema.Table {
// ====================================================================================================================

func fetchIotStreams(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
var diags diag.Diagnostics
input := iot.ListStreamsInput{
MaxResults: aws.Int32(250),
}
Expand All @@ -130,7 +131,7 @@ func fetchIotStreams(ctx context.Context, meta schema.ClientMeta, parent *schema
options.Region = c.Region
})
if err != nil {
return diag.WrapError(err)
return diags.Add(diag.FromError(diag.WrapError(err), diag.RESOLVING, diag.WithSeverity(diag.ERROR)))
}
for _, s := range response.Streams {
stream, err := svc.DescribeStream(ctx, &iot.DescribeStreamInput{
Expand All @@ -139,7 +140,9 @@ func fetchIotStreams(ctx context.Context, meta schema.ClientMeta, parent *schema
options.Region = c.Region
})
if err != nil {
return diag.WrapError(err)
// A single `Describe` call error should not end resolving of table
diags = diags.Add(diag.FromError(err, diag.RESOLVING, diag.WithSeverity(diag.WARNING)))
continue
}
res <- stream.StreamInfo
}
Expand All @@ -148,7 +151,7 @@ func fetchIotStreams(ctx context.Context, meta schema.ClientMeta, parent *schema
}
input.NextToken = response.NextToken
}
return nil
return diags
}
func fetchIotStreamFiles(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
i := parent.Item.(*types.StreamInfo)
Expand Down
7 changes: 4 additions & 3 deletions resources/services/lambda/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ func fetchLambdaFunctions(ctx context.Context, meta schema.ClientMeta, parent *s
options.Region = c.Region
})
if err != nil {
return diag.WrapError(err)
return diags.Add(diag.FromError(diag.WrapError(err), diag.RESOLVING, diag.WithSeverity(diag.ERROR)))
}

for _, f := range response.Functions {
Expand Down Expand Up @@ -1165,8 +1165,9 @@ func resolvePolicyCodeSigningConfig(ctx context.Context, meta schema.ClientMeta,
}

// skip getting CodeSigningConfig since containerized lambda functions does not support this feature
lambdaType := resource.Get("code_repository_type").(*string)
if *lambdaType == "ECR" {
// value can be nil if the caller doesn't have GetFunctionConfiguration permission and only has List*
lambdaType, ok := resource.Get("code_repository_type").(*string)
if !ok || *lambdaType == "ECR" {
return nil
}

Expand Down

0 comments on commit 9a55267

Please sign in to comment.