provider/aws: Update Lambda functions on name change (#7081)
Allows the updating of Lambda functions on name change alone
This commit is contained in:
parent
253a46b573
commit
5e26cb9960
|
@ -297,10 +297,11 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
|
|||
}
|
||||
|
||||
codeUpdate := false
|
||||
if v, ok := d.GetOk("filename"); ok && d.HasChange("source_code_hash") {
|
||||
file, err := loadFileContent(v.(string))
|
||||
if d.HasChange("filename") || d.HasChange("source_code_hash") {
|
||||
name := d.Get("filename").(string)
|
||||
file, err := loadFileContent(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to load %q: %s", v.(string), err)
|
||||
return fmt.Errorf("Unable to load %q: %s", name, err)
|
||||
}
|
||||
codeReq.ZipFile = file
|
||||
codeUpdate = true
|
||||
|
@ -312,8 +313,8 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
|
|||
codeUpdate = true
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Send Update Lambda Function Code request: %#v", codeReq)
|
||||
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)
|
||||
|
@ -352,8 +353,8 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
|
|||
configUpdate = true
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Send Update Lambda Function Configuration request: %#v", configReq)
|
||||
if configUpdate {
|
||||
log.Printf("[DEBUG] Send Update Lambda Function Configuration request: %#v", configReq)
|
||||
_, err := conn.UpdateFunctionConfiguration(configReq)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error modifying Lambda Function Configuration %s: %s", d.Id(), err)
|
||||
|
|
|
@ -129,6 +129,54 @@ func TestAccAWSLambdaFunction_localUpdate(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccAWSLambdaFunction_localUpdate_nameOnly(t *testing.T) {
|
||||
var conf lambda.GetFunctionOutput
|
||||
|
||||
path, zipFile, err := createTempFile("lambda_localUpdate")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(path)
|
||||
|
||||
updatedPath, updatedZipFile, err := createTempFile("lambda_localUpdate_name_change")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(updatedPath)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckLambdaFunctionDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
PreConfig: func() {
|
||||
testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func.js": "lambda.js"}, zipFile)
|
||||
},
|
||||
Config: genAWSLambdaFunctionConfig_local_name_only(path),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_local", "tf_acc_lambda_name_local", &conf),
|
||||
testAccCheckAwsLambdaFunctionName(&conf, "tf_acc_lambda_name_local"),
|
||||
testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, "tf_acc_lambda_name_local"),
|
||||
testAccCheckAwsLambdaSourceCodeHash(&conf, "un6qF9S9hKvXbWwJ6m2EYaVCWjcr0PCZWiTV3h4zB0I="),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
PreConfig: func() {
|
||||
testAccCreateZipFromFiles(map[string]string{"test-fixtures/lambda_func_modified.js": "lambda.js"}, updatedZipFile)
|
||||
},
|
||||
Config: genAWSLambdaFunctionConfig_local_name_only(updatedPath),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_local", "tf_acc_lambda_name_local", &conf),
|
||||
testAccCheckAwsLambdaFunctionName(&conf, "tf_acc_lambda_name_local"),
|
||||
testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, "tf_acc_lambda_name_local"),
|
||||
testAccCheckAwsLambdaSourceCodeHash(&conf, "Y5Jf4Si63UDy1wKNfPs+U56ZL0NxsieKPt9EwRl4GQM="),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSLambdaFunction_s3Update(t *testing.T) {
|
||||
var conf lambda.GetFunctionOutput
|
||||
|
||||
|
@ -505,6 +553,38 @@ func genAWSLambdaFunctionConfig_local(filePath string) string {
|
|||
filePath, filePath)
|
||||
}
|
||||
|
||||
func genAWSLambdaFunctionConfig_local_name_only(filePath string) string {
|
||||
return fmt.Sprintf(testAccAWSLambdaFunctionConfig_local_name_only_tpl,
|
||||
filePath)
|
||||
}
|
||||
|
||||
const testAccAWSLambdaFunctionConfig_local_name_only_tpl = `
|
||||
resource "aws_iam_role" "iam_for_lambda" {
|
||||
name = "iam_for_lambda"
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": "sts:AssumeRole",
|
||||
"Principal": {
|
||||
"Service": "lambda.amazonaws.com"
|
||||
},
|
||||
"Effect": "Allow",
|
||||
"Sid": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
resource "aws_lambda_function" "lambda_function_local" {
|
||||
filename = "%s"
|
||||
function_name = "tf_acc_lambda_name_local"
|
||||
role = "${aws_iam_role.iam_for_lambda.arn}"
|
||||
handler = "exports.example"
|
||||
}
|
||||
`
|
||||
|
||||
const testAccAWSLambdaFunctionConfig_s3_tpl = `
|
||||
resource "aws_s3_bucket" "artifacts" {
|
||||
bucket = "%s"
|
||||
|
|
Loading…
Reference in New Issue