diff --git a/aws/data_source_aws_lambda_layer_version.go b/aws/data_source_aws_lambda_layer_version.go index e2698b3b3a03..e3de48b63a74 100644 --- a/aws/data_source_aws_lambda_layer_version.go +++ b/aws/data_source_aws_lambda_layer_version.go @@ -28,7 +28,7 @@ func dataSourceAwsLambdaLayerVersion() *schema.Resource { "compatible_runtime": { Type: schema.TypeString, Optional: true, - ValidateFunc: validation.StringInSlice(validLambdaRuntimes, false), + ValidateFunc: validation.StringInSlice(lambda.Runtime_Values(), false), ConflictsWith: []string{"version"}, }, "compatible_runtimes": { diff --git a/aws/resource_aws_lambda_function.go b/aws/resource_aws_lambda_function.go index 3596322a86b3..8808e1d3c186 100644 --- a/aws/resource_aws_lambda_function.go +++ b/aws/resource_aws_lambda_function.go @@ -25,30 +25,6 @@ import ( const awsMutexLambdaKey = `aws_lambda_function` -var validLambdaRuntimes = []string{ - // lambda.RuntimeNodejs has reached end of life since October 2016 so not included here - lambda.RuntimeDotnetcore10, - lambda.RuntimeDotnetcore20, - lambda.RuntimeDotnetcore21, - lambda.RuntimeDotnetcore31, - lambda.RuntimeGo1X, - lambda.RuntimeJava8, - lambda.RuntimeJava11, - lambda.RuntimeNodejs43, - lambda.RuntimeNodejs43Edge, - lambda.RuntimeNodejs610, - lambda.RuntimeNodejs810, - lambda.RuntimeNodejs10X, - lambda.RuntimeNodejs12X, - lambda.RuntimeProvided, - lambda.RuntimePython27, - lambda.RuntimePython36, - lambda.RuntimePython37, - lambda.RuntimePython38, - lambda.RuntimeRuby25, - lambda.RuntimeRuby27, -} - func resourceAwsLambdaFunction() *schema.Resource { return &schema.Resource{ Create: resourceAwsLambdaFunctionCreate, @@ -166,7 +142,7 @@ func resourceAwsLambdaFunction() *schema.Resource { "runtime": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringInSlice(validLambdaRuntimes, false), + ValidateFunc: validation.StringInSlice(lambda.Runtime_Values(), false), }, "timeout": { Type: schema.TypeInt, diff --git a/aws/resource_aws_lambda_function_test.go b/aws/resource_aws_lambda_function_test.go index 427edf739d22..07905a205148 100644 --- a/aws/resource_aws_lambda_function_test.go +++ b/aws/resource_aws_lambda_function_test.go @@ -214,45 +214,6 @@ func TestAccAWSLambdaFunction_concurrencyCycle(t *testing.T) { }) } -func TestAccAWSLambdaFunction_updateRuntime(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - funcName := fmt.Sprintf("tf_acc_lambda_func_update_runtime_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_update_runtime_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_update_runtime_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_update_runtime_%s", rString) - resourceName := "aws_lambda_function.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigBasic(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", "nodejs12.x"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - { - Config: testAccAWSLambdaConfigBasicUpdateRuntime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", "nodejs10.x"), - ), - }, - }, - }) -} - func TestAccAWSLambdaFunction_expectFilenameAndS3Attributes(t *testing.T) { rString := acctest.RandString(8) funcName := fmt.Sprintf("tf_acc_lambda_func_expect_%s", rString) @@ -1327,186 +1288,6 @@ func TestAccAWSLambdaFunction_s3Update_unversioned(t *testing.T) { }) } -func TestAccAWSLambdaFunction_runtimeValidation_noRuntime(t *testing.T) { - rString := acctest.RandString(8) - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_no_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_no_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_no_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_no_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigNoRuntime(funcName, policyName, roleName, sgName), - ExpectError: regexp.MustCompile(`("runtime": required field is not set|The argument "runtime" is required)`), - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_NodeJs10x(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_nodejs10x_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_nodejs10x_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_nodejs10x_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_nodejs10x_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigNodeJs10xRuntime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeNodejs10X), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_NodeJs12x(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_nodejs12x_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_nodejs12x_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_nodejs12x_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_nodejs12x_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigNodeJs12xRuntime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeNodejs12X), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_python27(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_p27_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_p27_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_p27_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_p27_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigPython27Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimePython27), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_java8(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_j8_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_j8_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_j8_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_j8_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigJava8Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeJava8), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_java11(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_j11_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_j11_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_j11_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_j11_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigJava11Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeJava11), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - func TestAccAWSLambdaFunction_tags(t *testing.T) { var conf lambda.GetFunctionOutput @@ -1564,221 +1345,57 @@ func TestAccAWSLambdaFunction_tags(t *testing.T) { }) } -func TestAccAWSLambdaFunction_runtimeValidation_provided(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_provided_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_provided_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_provided_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_provided_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigProvidedRuntime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeProvided), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_python36(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) +func TestAccAWSLambdaFunction_runtimes(t *testing.T) { + var v lambda.GetFunctionOutput resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_p36_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_p36_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_p36_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_p36_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigPython36Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimePython36), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} -func TestAccAWSLambdaFunction_runtimeValidation_python37(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_p37_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_p37_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_p37_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_p37_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigPython37Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimePython37), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_python38(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_p38_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_p38_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_p38_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_p38_%s", rString) + rName := acctest.RandomWithPrefix("tf-acc-test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigPython38Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimePython38), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, + steps := []resource.TestStep{ + { + // Test invalid runtime. + Config: testAccAWSLambdaConfigRuntime(rName, rName), + ExpectError: regexp.MustCompile(`expected runtime to be one of`), }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_ruby25(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_r25_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_r25_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_r25_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_r25_%s", rString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigRuby25Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeRuby25), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, - }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_ruby27(t *testing.T) { - var conf lambda.GetFunctionOutput - - rString := acctest.RandString(8) - resourceName := "aws_lambda_function.test" - funcName := fmt.Sprintf("tf_acc_lambda_func_runtime_valid_r27_%s", rString) - policyName := fmt.Sprintf("tf_acc_policy_lambda_func_runtime_valid_r27_%s", rString) - roleName := fmt.Sprintf("tf_acc_role_lambda_func_runtime_valid_r27_%s", rString) - sgName := fmt.Sprintf("tf_acc_sg_lambda_func_runtime_valid_r27_%s", rString) + } + for _, runtime := range lambda.Runtime_Values() { + // EOL runtimes. + switch runtime { + case lambda.RuntimeNodejs43Edge: + fallthrough + case lambda.RuntimeDotnetcore20: + fallthrough + case lambda.RuntimeDotnetcore10: + fallthrough + case lambda.RuntimeNodejs810: + fallthrough + case lambda.RuntimeNodejs610: + fallthrough + case lambda.RuntimeNodejs43: + fallthrough + case lambda.RuntimeNodejs: + continue + } - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigRuby27Runtime(funcName, policyName, roleName, sgName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeRuby27), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, + steps = append(steps, resource.TestStep{ + Config: testAccAWSLambdaConfigRuntime(rName, runtime), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsLambdaFunctionExists(resourceName, rName, &v), + resource.TestCheckResourceAttr(resourceName, "runtime", runtime), + ), + }) + } + steps = append(steps, resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"filename", "publish"}, }) -} - -func TestAccAWSLambdaFunction_runtimeValidation_dotnetcore31(t *testing.T) { - var conf lambda.GetFunctionOutput - rName := acctest.RandomWithPrefix("tf-acc-test") - resourceName := "aws_lambda_function.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLambdaFunctionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSLambdaConfigDotNetCore31Runtime(rName, rName, rName, rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaFunctionExists(resourceName, rName, &conf), - resource.TestCheckResourceAttr(resourceName, "runtime", lambda.RuntimeDotnetcore31), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"filename", "publish"}, - }, - }, + Steps: steps, }) } @@ -2148,18 +1765,6 @@ resource "aws_lambda_function" "test" { `, funcName) } -func testAccAWSLambdaConfigBasicUpdateRuntime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "nodejs10.x" -} -`, funcName) -} - func testAccAWSLambdaConfigWithoutFilenameAndS3Attributes(funcName, policyName, roleName, sgName string) string { return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` resource "aws_lambda_function" "test" { @@ -2811,77 +2416,6 @@ resource "aws_lambda_function" "test" { `, bucketName, roleName, funcName) } -func testAccAWSLambdaConfigNoRuntime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" -} -`, funcName) -} - -func testAccAWSLambdaConfigNodeJs10xRuntime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "nodejs10.x" -} -`, funcName) -} - -func testAccAWSLambdaConfigNodeJs12xRuntime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "nodejs12.x" -} -`, funcName) -} - -func testAccAWSLambdaConfigPython27Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_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" -} -`, funcName) -} - -func testAccAWSLambdaConfigJava8Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "java8" -} -`, funcName) -} - -func testAccAWSLambdaConfigJava11Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "java11" -} -`, funcName) -} - func testAccAWSLambdaConfigTags(funcName, policyName, roleName, sgName string) string { return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` resource "aws_lambda_function" "test" { @@ -2917,90 +2451,6 @@ resource "aws_lambda_function" "test" { `, funcName) } -func testAccAWSLambdaConfigProvidedRuntime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "provided" -} -`, funcName) -} - -func testAccAWSLambdaConfigPython36Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "python3.6" -} -`, funcName) -} - -func testAccAWSLambdaConfigPython37Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "python3.7" -} -`, funcName) -} - -func testAccAWSLambdaConfigPython38Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "python3.8" -} -`, funcName) -} - -func testAccAWSLambdaConfigRuby25Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "ruby2.5" -} -`, funcName) -} - -func testAccAWSLambdaConfigRuby27Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "ruby2.7" -} -`, funcName) -} - -func testAccAWSLambdaConfigDotNetCore31Runtime(funcName, policyName, roleName, sgName string) string { - return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+` -resource "aws_lambda_function" "test" { - filename = "test-fixtures/lambdatest.zip" - function_name = "%s" - role = aws_iam_role.iam_for_lambda.arn - handler = "exports.example" - runtime = "dotnetcore3.1" -} -`, funcName) -} - func genAWSLambdaFunctionConfig_local(filePath, roleName, funcName string) string { return fmt.Sprintf(` resource "aws_iam_role" "iam_for_lambda" { @@ -3170,3 +2620,17 @@ resource "aws_lambda_function" "test" { } `, bucketName, key, path, path, roleName, funcName) } + +func testAccAWSLambdaConfigRuntime(rName, runtime string) string { + return composeConfig( + baseAccAWSLambdaConfig(rName, rName, rName), + fmt.Sprintf(` +resource "aws_lambda_function" "test" { + filename = "test-fixtures/lambdatest.zip" + function_name = %[1]q + role = aws_iam_role.iam_for_lambda.arn + handler = "exports.example" + runtime = %[2]q +} +`, rName, runtime)) +} diff --git a/aws/resource_aws_lambda_layer_version.go b/aws/resource_aws_lambda_layer_version.go index 9248901daa24..69109e5b8032 100644 --- a/aws/resource_aws_lambda_layer_version.go +++ b/aws/resource_aws_lambda_layer_version.go @@ -64,7 +64,7 @@ func resourceAwsLambdaLayerVersion() *schema.Resource { MaxItems: 5, Elem: &schema.Schema{ Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(validLambdaRuntimes, false), + ValidateFunc: validation.StringInSlice(lambda.Runtime_Values(), false), }, }, "description": { diff --git a/website/docs/r/apigatewayv2_integration.html.markdown b/website/docs/r/apigatewayv2_integration.html.markdown index faca58d33fca..be0b07eee31f 100644 --- a/website/docs/r/apigatewayv2_integration.html.markdown +++ b/website/docs/r/apigatewayv2_integration.html.markdown @@ -30,7 +30,7 @@ resource "aws_lambda_function" "example" { function_name = "Example" role = aws_iam_role.example.arn handler = "index.handler" - runtime = "nodejs10.x" + runtime = "nodejs12.x" } resource "aws_apigatewayv2_integration" "example" { diff --git a/website/docs/r/kinesis_firehose_delivery_stream.html.markdown b/website/docs/r/kinesis_firehose_delivery_stream.html.markdown index 50b753f89164..ac959897e397 100644 --- a/website/docs/r/kinesis_firehose_delivery_stream.html.markdown +++ b/website/docs/r/kinesis_firehose_delivery_stream.html.markdown @@ -90,7 +90,7 @@ resource "aws_lambda_function" "lambda_processor" { function_name = "firehose_lambda_processor" role = aws_iam_role.lambda_iam.arn handler = "exports.handler" - runtime = "nodejs8.10" + runtime = "nodejs12.x" } ``` diff --git a/website/docs/r/lambda_layer_version.html.markdown b/website/docs/r/lambda_layer_version.html.markdown index e6840db13af9..0db762e19366 100644 --- a/website/docs/r/lambda_layer_version.html.markdown +++ b/website/docs/r/lambda_layer_version.html.markdown @@ -19,7 +19,7 @@ resource "aws_lambda_layer_version" "lambda_layer" { filename = "lambda_layer_payload.zip" layer_name = "lambda_layer_name" - compatible_runtimes = ["nodejs8.10"] + compatible_runtimes = ["nodejs12.x"] } ``` diff --git a/website/docs/r/lambda_permission.html.markdown b/website/docs/r/lambda_permission.html.markdown index 04ecb8444f8a..c49fa51e18c4 100644 --- a/website/docs/r/lambda_permission.html.markdown +++ b/website/docs/r/lambda_permission.html.markdown @@ -34,7 +34,7 @@ resource "aws_lambda_function" "test_lambda" { function_name = "lambda_function_name" role = aws_iam_role.iam_for_lambda.arn handler = "exports.handler" - runtime = "nodejs8.10" + runtime = "nodejs12.x" } resource "aws_iam_role" "iam_for_lambda" {