Attempt to fix #6794 - update only non empty fields on aws_lambda_function s3

This commit is contained in:
Alex Eftimie 2016-05-24 23:39:35 +02:00 committed by Martin Atkins
parent 39d68025a5
commit c5f788ec58
1 changed files with 25 additions and 13 deletions

View File

@ -306,21 +306,33 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
} }
codeUpdate := false codeUpdate := false
if d.HasChange("filename") || d.HasChange("source_code_hash") { if v, ok := d.GetOk("filename"); ok {
name := d.Get("filename").(string) if d.HasChange("source_code_hash") {
file, err := loadFileContent(name) file, err := loadFileContent(v.(string))
if err != nil { if err != nil {
return fmt.Errorf("Unable to load %q: %s", name, err) return fmt.Errorf("Unable to load %q: %s", v.(string), err)
} }
codeReq.ZipFile = file codeReq.ZipFile = file
codeUpdate = true codeUpdate = true
} }
if d.HasChange("s3_bucket") || d.HasChange("s3_key") || d.HasChange("s3_object_version") { } else {
codeReq.S3Bucket = aws.String(d.Get("s3_bucket").(string)) s3Bucket, bucketOk := d.GetOk("s3_bucket")
codeReq.S3Key = aws.String(d.Get("s3_key").(string)) s3Key, keyOk := d.GetOk("s3_key")
codeReq.S3ObjectVersion = aws.String(d.Get("s3_object_version").(string)) s3ObjectVersion, versionOk := d.GetOk("s3_object_version")
if bucketOk && d.HasChange("s3_bucket") {
codeReq.S3Bucket = aws.String(s3Bucket.(string))
codeUpdate = true codeUpdate = true
} }
if keyOk && d.HasChange("s3_key") {
codeReq.S3Key = aws.String(s3Key.(string))
codeUpdate = true
}
if versionOk && d.HasChange("s3_object_version") {
codeReq.S3ObjectVersion = aws.String(s3ObjectVersion.(string))
codeUpdate = true
}
}
if codeUpdate { if codeUpdate {
log.Printf("[DEBUG] Send Update Lambda Function Code request: %#v", codeReq) log.Printf("[DEBUG] Send Update Lambda Function Code request: %#v", codeReq)