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)
|
d.Partial(true)
|
||||||
|
|
||||||
codeReq := &lambda.UpdateFunctionCodeInput{
|
if d.HasChange("filename") || d.HasChange("source_code_hash") || d.HasChange("s3_bucket") || d.HasChange("s3_key") || d.HasChange("s3_object_version") {
|
||||||
FunctionName: aws.String(d.Id()),
|
codeReq := &lambda.UpdateFunctionCodeInput{
|
||||||
}
|
FunctionName: aws.String(d.Id()),
|
||||||
|
}
|
||||||
|
|
||||||
codeUpdate := false
|
if v, ok := d.GetOk("filename"); ok {
|
||||||
if v, ok := d.GetOk("filename"); ok {
|
|
||||||
if d.HasChange("source_code_hash") {
|
|
||||||
file, err := loadFileContent(v.(string))
|
file, err := loadFileContent(v.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to load %q: %s", v.(string), err)
|
return fmt.Errorf("Unable to load %q: %s", v.(string), err)
|
||||||
}
|
}
|
||||||
codeReq.ZipFile = file
|
codeReq.ZipFile = file
|
||||||
codeUpdate = true
|
} else {
|
||||||
}
|
s3Bucket, _ := d.GetOk("s3_bucket")
|
||||||
} else {
|
s3Key, _ := d.GetOk("s3_key")
|
||||||
s3Bucket, bucketOk := d.GetOk("s3_bucket")
|
s3ObjectVersion, versionOk := d.GetOk("s3_object_version")
|
||||||
s3Key, keyOk := d.GetOk("s3_key")
|
|
||||||
s3ObjectVersion, versionOk := d.GetOk("s3_object_version")
|
|
||||||
|
|
||||||
if bucketOk && keyOk {
|
codeReq.S3Bucket = aws.String(s3Bucket.(string))
|
||||||
if d.HasChange("s3_bucket") || d.HasChange("s3_key") {
|
codeReq.S3Key = aws.String(s3Key.(string))
|
||||||
codeReq.S3Bucket = aws.String(s3Bucket.(string))
|
if versionOk {
|
||||||
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))
|
|
||||||
codeReq.S3ObjectVersion = aws.String(s3ObjectVersion.(string))
|
codeReq.S3ObjectVersion = aws.String(s3ObjectVersion.(string))
|
||||||
codeUpdate = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if codeUpdate {
|
|
||||||
log.Printf("[DEBUG] Send Update Lambda Function Code request: %#v", codeReq)
|
log.Printf("[DEBUG] Send Update Lambda Function Code request: %#v", codeReq)
|
||||||
|
|
||||||
_, err := conn.UpdateFunctionCode(codeReq)
|
_, err := conn.UpdateFunctionCode(codeReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error modifying Lambda Function Code %s: %s", d.Id(), err)
|
return fmt.Errorf("Error modifying Lambda Function Code %s: %s", d.Id(), err)
|
||||||
|
|
Loading…
Reference in New Issue