-
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
Conversation
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, there's no need to wrap this again
@@ -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 { |
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.
FYI @bflad, this hard fail caused us a lot of grief today. If we can get this drift-remediation update included then our work-around for the modified lambda policies will be a terraform upgrade instead of us having to modify 40-50 TFE project state files or out-of-band edit of lambda permissions. |
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.
Thanks for the PR, @ansoni. Could you add acceptance tests for this, please?
You can probably use direct AWS API calls to make the out-of-band changes. Take a look at some of the <something>_disappears
acceptance tests for inspiration.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, there's no need to wrap this again
@gdavison I wrote an acceptance test for this Running tool: /usr/local/bin/go test -timeout 30s github.com/terraform-providers/terraform-provider-aws/aws -run ^(TestAccAWSLambdaPermission_disappears)$ |
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.
Thanks for the test, @scottwinkler. I have a couple changes.
{ | ||
Config: testAccAWSLambdaPermissionConfig(funcName, roleName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckLambdaPermissionExists("aws_lambda_permission.allow_cloudwatch", &statement), | ||
), | ||
}, | ||
// Here we delete the Lambda permission to verify the follow-on refresh after this step | ||
// should not error. |
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.
This first step can be removed
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.
removed
// Here we delete the Lambda permission to verify the follow-on refresh after this step | ||
// should not error. | ||
{ | ||
Config: testAccAWSLambdaPermissionConfig(funcName, roleName), |
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.
The error only shows up when there are still permission elements left. We can use testAccAWSLambdaPermissionConfig_multiplePerms()
instead, and then remove aws_lambda_permission.first
.
@gdavison I made the changes you requested. Please let me know if there is anything else you require |
LGTM 🚀 --- PASS: TestAccAWSLambdaPermission_basic (24.64s) |
This has been released in version 2.50.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Hello,
Please find the small change to blank out the Id for proper remediation when the policy SID goes missing.
Thanks,
Anthony
Community Note
Closes #11008
Release note for CHANGELOG:
Output from acceptance testing: