-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
provider/aws: Don't delete Lambda function from state on initial call of the Read func #7829
Conversation
the Read func Fixes #7782 Lambda functions are eventually consistent :( Therefore, when we move from the Create func to the Read func, there is a chance that the Lambda hasn't replicated yet and we could therefore find that it doesn't exist and delete it as follows: ``` params := &lambda.GetFunctionInput{ FunctionName: aws.String(d.Get("function_name").(string)), } getFunctionOutput, err := conn.GetFunction(params) if err != nil { if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" { d.SetId("") return nil } return err } ``` This PR uses `d.IsNewResource()` to check if the Read is being called after a Create and therefore, won't delete the lambda if not found. This should allow the lambda to replicate ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSLambdaFunction_' => Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSLambdaFunction_ -timeout 120m === RUN TestAccAWSLambdaFunction_importLocalFile --- PASS: TestAccAWSLambdaFunction_importLocalFile (36.64s) === RUN TestAccAWSLambdaFunction_importLocalFile_VPC --- PASS: TestAccAWSLambdaFunction_importLocalFile_VPC (45.17s) === RUN TestAccAWSLambdaFunction_importS3 --- PASS: TestAccAWSLambdaFunction_importS3 (40.88s) === RUN TestAccAWSLambdaFunction_basic --- PASS: TestAccAWSLambdaFunction_basic (44.77s) === RUN TestAccAWSLambdaFunction_VPC --- PASS: TestAccAWSLambdaFunction_VPC (44.13s) === RUN TestAccAWSLambdaFunction_s3 --- PASS: TestAccAWSLambdaFunction_s3 (43.62s) === RUN TestAccAWSLambdaFunction_localUpdate --- PASS: TestAccAWSLambdaFunction_localUpdate (33.49s) === RUN TestAccAWSLambdaFunction_localUpdate_nameOnly --- PASS: TestAccAWSLambdaFunction_localUpdate_nameOnly (51.83s) === RUN TestAccAWSLambdaFunction_s3Update --- PASS: TestAccAWSLambdaFunction_s3Update (106.49s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 447.055s ``` Thanks to @radeksimko for pointing out `d.IsNewResource()`
@@ -237,7 +237,7 @@ func resourceAwsLambdaFunctionRead(d *schema.ResourceData, meta interface{}) err | |||
|
|||
getFunctionOutput, err := conn.GetFunction(params) | |||
if err != nil { | |||
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" { | |||
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" && !d.IsNewResource() { |
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.
I know it's unrelated to the original intention behind this PR, but it would be great to have a [WARN]
log message here, like we have in most other resources. 😉
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.
Funny you mention that, there will be a little more standardisation in this area.... soon ™️
This LGTM. |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Fixes #7782
Lambda functions are eventually consistent :( Therefore, when we move
from the Create func to the Read func, there is a chance that the Lambda
hasn't replicated yet and we could therefore find that it doesn't exist
and delete it as follows:
This PR uses
d.IsNewResource()
to check if the Read is being calledafter a Create and therefore, won't delete the lambda if not found. This
should allow the lambda to replicate
Thanks to @radeksimko for pointing out
d.IsNewResource()