-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
re-create lambda policy when permission sid not found #11924
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,16 @@ func resourceAwsLambdaPermissionRead(d *schema.ResourceData, meta interface{}) e | |
if err == nil { | ||
var psErr error | ||
statement, psErr = getLambdaPolicyStatement(out, d.Id()) | ||
|
||
// handle the resource not existing | ||
if awsErr, ok := psErr.(awserr.Error); ok { | ||
if awsErr.Code() == "ResourceNotFoundException" { | ||
log.Printf("[WARN] No Lambda Permission Policy found: %v", input) | ||
d.SetId("") | ||
return nil | ||
} | ||
} | ||
|
||
if psErr != nil { | ||
return psErr | ||
} | ||
|
@@ -385,7 +395,6 @@ func resourceAwsLambdaPermissionDelete(d *schema.ResourceData, meta interface{}) | |
|
||
return nil | ||
} | ||
|
||
func getLambdaPolicyStatement(out *lambda.GetPolicyOutput, statemendId string) (statement *LambdaPolicyStatement, err error) { | ||
policyInBytes := []byte(*out.Policy) | ||
policy := LambdaPolicy{} | ||
|
@@ -394,11 +403,7 @@ func getLambdaPolicyStatement(out *lambda.GetPolicyOutput, statemendId string) ( | |
return nil, fmt.Errorf("Error unmarshalling Lambda policy: %s", err) | ||
} | ||
|
||
statement, psErr := findLambdaPolicyStatementById(&policy, statemendId) | ||
if psErr != nil { | ||
return nil, fmt.Errorf("Error finding Lambda policy statement: %s", psErr) | ||
} | ||
return statement, nil | ||
return findLambdaPolicyStatementById(&policy, statemendId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re-casting the error to a human readable string is unnecessary since we are a tool that can do something about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, there's no need to wrap this again |
||
} | ||
|
||
func findLambdaPolicyStatementById(policy *LambdaPolicy, id string) ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern taken from existing code a few lines below. I don't believe we were ever hitting that case, but left just to be sure.