provider/aws: Deprecated aws_lambda_function nodejs runtime in favor of nodejs4.3 (#9724)

* provider/aws/lambda: Deprecated nodejs in favor of nodejs4.3

* Removed redundant type declarations in composite literals

* Added validation tests
This commit is contained in:
Ninir 2016-12-16 13:24:45 +01:00 committed by Paul Stack
parent a04fbf8c45
commit f96e45ba56
3 changed files with 198 additions and 28 deletions

View File

@ -77,10 +77,10 @@ func resourceAwsLambdaFunction() *schema.Resource {
Required: true,
},
"runtime": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "nodejs",
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateRuntime,
},
"timeout": {
Type: schema.TypeInt,
@ -575,3 +575,14 @@ func validateVPCConfig(v interface{}) (map[string]interface{}, error) {
return config, nil
}
func validateRuntime(v interface{}, k string) (ws []string, errors []error) {
runtime := v.(string)
if runtime == lambda.RuntimeNodejs {
errors = append(errors, fmt.Errorf(
"%s has reached end of life since October 2016 and has been deprecated in favor of %s.",
runtime, lambda.RuntimeNodejs43))
}
return
}

View File

@ -346,7 +346,7 @@ func TestAccAWSLambdaFunction_s3Update(t *testing.T) {
},
// Extra step because of missing ComputedWhen
// See https://github.com/hashicorp/terraform/pull/4846 & https://github.com/hashicorp/terraform/pull/5330
resource.TestStep{
{
Config: genAWSLambdaFunctionConfig_s3(bucketName, key, path),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_s3", "tf_acc_lambda_name_s3", &conf),
@ -407,6 +407,98 @@ func TestAccAWSLambdaFunction_s3Update_unversioned(t *testing.T) {
})
}
func TestAccAWSLambdaFunction_runtimeValidation_noRuntime(t *testing.T) {
rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigNoRuntime(rName),
ExpectError: regexp.MustCompile(`\\"runtime\\": required field is not set`),
},
},
})
}
func TestAccAWSLambdaFunction_runtimeValidation_nodeJs(t *testing.T) {
rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigNodeJsRuntime(rName),
ExpectError: regexp.MustCompile(fmt.Sprintf("%s has reached end of life since October 2016 and has been deprecated in favor of %s", lambda.RuntimeNodejs, lambda.RuntimeNodejs43)),
},
},
})
}
func TestAccAWSLambdaFunction_runtimeValidation_nodeJs43(t *testing.T) {
var conf lambda.GetFunctionOutput
rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigNodeJs43Runtime(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf),
resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "runtime", lambda.RuntimeNodejs43),
),
},
},
})
}
func TestAccAWSLambdaFunction_runtimeValidation_python27(t *testing.T) {
var conf lambda.GetFunctionOutput
rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigPython27Runtime(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf),
resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "runtime", lambda.RuntimePython27),
),
},
},
})
}
func TestAccAWSLambdaFunction_runtimeValidation_java8(t *testing.T) {
var conf lambda.GetFunctionOutput
rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigJava8Runtime(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf),
resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "runtime", lambda.RuntimeJava8),
),
},
},
})
}
func testAccCheckLambdaFunctionDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).lambdaconn
@ -637,6 +729,7 @@ resource "aws_lambda_function" "lambda_function_test" {
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`, rName)
}
@ -757,6 +850,7 @@ resource "aws_lambda_function" "lambda_function_test" {
publish = true
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`, rName)
}
@ -768,6 +862,7 @@ resource "aws_lambda_function" "lambda_function_test" {
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
vpc_config = {
subnet_ids = ["${aws_subnet.subnet_for_lambda.id}"]
@ -813,10 +908,70 @@ resource "aws_lambda_function" "lambda_function_s3test" {
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`, acctest.RandInt(), rName)
}
func testAccAWSLambdaConfigNoRuntime(rName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig+`
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
}
`, rName)
}
func testAccAWSLambdaConfigNodeJsRuntime(rName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig+`
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs"
}
`, rName)
}
func testAccAWSLambdaConfigNodeJs43Runtime(rName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig+`
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`, rName)
}
func testAccAWSLambdaConfigPython27Runtime(rName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig+`
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "python2.7"
}
`, rName)
}
func testAccAWSLambdaConfigJava8Runtime(rName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig+`
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "java8"
}
`, rName)
}
const testAccAWSLambdaFunctionConfig_local_tpl = `
resource "aws_iam_role" "iam_for_lambda" {
name = "iam_for_lambda"
@ -842,6 +997,7 @@ resource "aws_lambda_function" "lambda_function_local" {
function_name = "tf_acc_lambda_name_local"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`
@ -879,23 +1035,24 @@ resource "aws_lambda_function" "lambda_function_local" {
function_name = "tf_acc_lambda_name_local"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`
const testAccAWSLambdaFunctionConfig_s3_tpl = `
resource "aws_s3_bucket" "artifacts" {
bucket = "%s"
acl = "private"
force_destroy = true
versioning {
enabled = true
}
bucket = "%s"
acl = "private"
force_destroy = true
versioning {
enabled = true
}
}
resource "aws_s3_bucket_object" "o" {
bucket = "${aws_s3_bucket.artifacts.bucket}"
key = "%s"
source = "%s"
etag = "${md5(file("%s"))}"
bucket = "${aws_s3_bucket.artifacts.bucket}"
key = "%s"
source = "%s"
etag = "${md5(file("%s"))}"
}
resource "aws_iam_role" "iam_for_lambda" {
name = "iam_for_lambda"
@ -916,12 +1073,13 @@ resource "aws_iam_role" "iam_for_lambda" {
EOF
}
resource "aws_lambda_function" "lambda_function_s3" {
s3_bucket = "${aws_s3_bucket_object.o.bucket}"
s3_key = "${aws_s3_bucket_object.o.key}"
s3_object_version = "${aws_s3_bucket_object.o.version_id}"
s3_bucket = "${aws_s3_bucket_object.o.bucket}"
s3_key = "${aws_s3_bucket_object.o.key}"
s3_object_version = "${aws_s3_bucket_object.o.version_id}"
function_name = "tf_acc_lambda_name_s3"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`
@ -932,15 +1090,15 @@ func genAWSLambdaFunctionConfig_s3(bucket, key, path string) string {
const testAccAWSLambdaFunctionConfig_s3_unversioned_tpl = `
resource "aws_s3_bucket" "artifacts" {
bucket = "%s"
acl = "private"
force_destroy = true
bucket = "%s"
acl = "private"
force_destroy = true
}
resource "aws_s3_bucket_object" "o" {
bucket = "${aws_s3_bucket.artifacts.bucket}"
key = "%s"
source = "%s"
etag = "${md5(file("%s"))}"
bucket = "${aws_s3_bucket.artifacts.bucket}"
key = "%s"
source = "%s"
etag = "${md5(file("%s"))}"
}
resource "aws_iam_role" "iam_for_lambda" {
name = "iam_for_lambda"
@ -961,11 +1119,12 @@ resource "aws_iam_role" "iam_for_lambda" {
EOF
}
resource "aws_lambda_function" "lambda_function_s3" {
s3_bucket = "${aws_s3_bucket_object.o.bucket}"
s3_key = "${aws_s3_bucket_object.o.key}"
s3_bucket = "${aws_s3_bucket_object.o.bucket}"
s3_key = "${aws_s3_bucket_object.o.key}"
function_name = "tf_acc_lambda_name_s3_unversioned"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
runtime = "nodejs4.3"
}
`

View File

@ -59,7 +59,7 @@ resource "aws_lambda_function" "test_lambda" {
* `role` - (Required) IAM role attached to the Lambda Function. This governs both who / what can invoke your Lambda Function, as well as what resources our Lambda Function has access to. See [Lambda Permission Model][4] for more details.
* `description` - (Optional) Description of what your Lambda Function does.
* `memory_size` - (Optional) Amount of memory in MB your Lambda Function can use at runtime. Defaults to `128`. See [Limits][5]
* `runtime` - (Optional) Defaults to `nodejs`. See [Runtimes][6] for valid values.
* `runtime` - (Required) See [Runtimes][6] for valid values.
* `timeout` - (Optional) The amount of time your Lambda Function has to run in seconds. Defaults to `3`. See [Limits][5]
* `publish` - (Optional) Whether to publish creation/change as new Lambda Function Version. Defaults to `false`.
* `vpc_config` - (Optional) Provide this to allow your function to access your VPC. Fields documented below. See [Lambda in VPC][7]