|
|
|
|
@ -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"
|
|
|
|
|
|