Refactor for code simplicity.
This commit is contained in:
parent
d44ae5028f
commit
3a97971e41
|
@ -301,43 +301,31 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
d.Partial(true)
|
||||
|
||||
if d.HasChange("filename") || d.HasChange("source_code_hash") || d.HasChange("s3_bucket") || d.HasChange("s3_key") || d.HasChange("s3_object_version") {
|
||||
codeReq := &lambda.UpdateFunctionCodeInput{
|
||||
FunctionName: aws.String(d.Id()),
|
||||
}
|
||||
|
||||
codeUpdate := false
|
||||
if v, ok := d.GetOk("filename"); ok {
|
||||
if d.HasChange("source_code_hash") {
|
||||
file, err := loadFileContent(v.(string))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to load %q: %s", v.(string), err)
|
||||
}
|
||||
codeReq.ZipFile = file
|
||||
codeUpdate = true
|
||||
}
|
||||
} else {
|
||||
s3Bucket, bucketOk := d.GetOk("s3_bucket")
|
||||
s3Key, keyOk := d.GetOk("s3_key")
|
||||
s3Bucket, _ := d.GetOk("s3_bucket")
|
||||
s3Key, _ := d.GetOk("s3_key")
|
||||
s3ObjectVersion, versionOk := d.GetOk("s3_object_version")
|
||||
|
||||
if bucketOk && keyOk {
|
||||
if d.HasChange("s3_bucket") || d.HasChange("s3_key") {
|
||||
codeReq.S3Bucket = aws.String(s3Bucket.(string))
|
||||
codeReq.S3Key = aws.String(s3Key.(string))
|
||||
codeUpdate = true
|
||||
}
|
||||
|
||||
if versionOk && d.HasChange("s3_object_version") {
|
||||
codeReq.S3Bucket = aws.String(s3Bucket.(string))
|
||||
codeReq.S3Key = aws.String(s3Key.(string))
|
||||
if versionOk {
|
||||
codeReq.S3ObjectVersion = aws.String(s3ObjectVersion.(string))
|
||||
codeUpdate = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if codeUpdate {
|
||||
log.Printf("[DEBUG] Send Update Lambda Function Code request: %#v", codeReq)
|
||||
|
||||
_, err := conn.UpdateFunctionCode(codeReq)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error modifying Lambda Function Code %s: %s", d.Id(), err)
|
||||
|
|
Loading…
Reference in New Issue