-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
resource/aws_lambda_function: Recompute Lambda function version and qualified_arn on publish #3032
Changes from 2 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 |
---|---|---|
|
@@ -200,9 +200,21 @@ func resourceAwsLambdaFunction() *schema.Resource { | |
|
||
"tags": tagsSchema(), | ||
}, | ||
|
||
CustomizeDiff: updateComputedAttributesOnPublish, | ||
} | ||
} | ||
|
||
func updateComputedAttributesOnPublish(d *schema.ResourceDiff, meta interface{}) error { | ||
publish := d.Get("publish").(bool) | ||
if publish && needsFunctionCodeUpdate(d) { | ||
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. What if you did the following. It would make sure the last_modified was updated even if publish is set to false.
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. Check out the new commit. It should cover your scenario now too |
||
d.SetNewComputed("version") | ||
d.SetNewComputed("qualified_arn") | ||
d.SetNewComputed("last_modified") | ||
} | ||
return nil | ||
} | ||
|
||
// resourceAwsLambdaFunction maps to: | ||
// CreateFunction in the API / SDK | ||
func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) error { | ||
|
@@ -521,6 +533,14 @@ func resourceAwsLambdaFunctionDelete(d *schema.ResourceData, meta interface{}) e | |
return nil | ||
} | ||
|
||
type resourceDiffer interface { | ||
HasChange(string) bool | ||
} | ||
|
||
func needsFunctionCodeUpdate(d resourceDiffer) bool { | ||
return d.HasChange("filename") || d.HasChange("source_code_hash") || d.HasChange("s3_bucket") || d.HasChange("s3_key") || d.HasChange("s3_object_version") | ||
} | ||
|
||
// resourceAwsLambdaFunctionUpdate maps to: | ||
// UpdateFunctionCode in the API / SDK | ||
func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) error { | ||
|
@@ -664,7 +684,7 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e | |
d.SetPartial("timeout") | ||
} | ||
|
||
if d.HasChange("filename") || d.HasChange("source_code_hash") || d.HasChange("s3_bucket") || d.HasChange("s3_key") || d.HasChange("s3_object_version") { | ||
if needsFunctionCodeUpdate(d) { | ||
codeReq := &lambda.UpdateFunctionCodeInput{ | ||
FunctionName: aws.String(d.Id()), | ||
Publish: aws.Bool(d.Get("publish").(bool)), | ||
|
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.
There are two other attributes that need to be SetNewComputed:
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.
Thank you for the feedback. I implemented the changes for last_modified and qualified_arn. In this version I only updated last_modified during the publish, but I see your point about it being needed more often than that.