diff --git a/builtin/providers/aws/import_aws_lambda_function_test.go b/builtin/providers/aws/import_aws_lambda_function_test.go index 2ab7eac6b..877c442a8 100644 --- a/builtin/providers/aws/import_aws_lambda_function_test.go +++ b/builtin/providers/aws/import_aws_lambda_function_test.go @@ -11,7 +11,8 @@ import ( func TestAccAWSLambdaFunction_importLocalFile(t *testing.T) { resourceName := "aws_lambda_function.lambda_function_test" - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -19,7 +20,7 @@ func TestAccAWSLambdaFunction_importLocalFile(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSLambdaConfigBasic(rName), + Config: testAccAWSLambdaConfigBasic(rName, rSt), }, resource.TestStep{ @@ -35,7 +36,8 @@ func TestAccAWSLambdaFunction_importLocalFile(t *testing.T) { func TestAccAWSLambdaFunction_importLocalFile_VPC(t *testing.T) { resourceName := "aws_lambda_function.lambda_function_test" - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -43,7 +45,7 @@ func TestAccAWSLambdaFunction_importLocalFile_VPC(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSLambdaConfigWithVPC(rName), + Config: testAccAWSLambdaConfigWithVPC(rName, rSt), }, resource.TestStep{ @@ -59,7 +61,8 @@ func TestAccAWSLambdaFunction_importLocalFile_VPC(t *testing.T) { func TestAccAWSLambdaFunction_importS3(t *testing.T) { resourceName := "aws_lambda_function.lambda_function_s3test" - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -67,7 +70,7 @@ func TestAccAWSLambdaFunction_importS3(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSLambdaConfigS3(rName), + Config: testAccAWSLambdaConfigS3(rName, rSt), }, resource.TestStep{ diff --git a/builtin/providers/aws/resource_aws_lambda_function_test.go b/builtin/providers/aws/resource_aws_lambda_function_test.go index 1a0f1c4fb..4cc5d92d8 100644 --- a/builtin/providers/aws/resource_aws_lambda_function_test.go +++ b/builtin/providers/aws/resource_aws_lambda_function_test.go @@ -20,7 +20,8 @@ import ( func TestAccAWSLambdaFunction_basic(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -28,7 +29,7 @@ func TestAccAWSLambdaFunction_basic(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigBasic(rName), + Config: testAccAWSLambdaConfigBasic(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -40,7 +41,8 @@ func TestAccAWSLambdaFunction_basic(t *testing.T) { } func TestAccAWSLambdaFunction_expectFilenameAndS3Attributes(t *testing.T) { - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -48,7 +50,7 @@ func TestAccAWSLambdaFunction_expectFilenameAndS3Attributes(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigWithoutFilenameAndS3Attributes(rName), + Config: testAccAWSLambdaConfigWithoutFilenameAndS3Attributes(rName, rSt), ExpectError: regexp.MustCompile(`filename or s3_\* attributes must be set`), }, }, @@ -58,7 +60,8 @@ func TestAccAWSLambdaFunction_expectFilenameAndS3Attributes(t *testing.T) { func TestAccAWSLambdaFunction_envVariables(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -66,7 +69,7 @@ func TestAccAWSLambdaFunction_envVariables(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigBasic(rName), + Config: testAccAWSLambdaConfigBasic(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -75,7 +78,7 @@ func TestAccAWSLambdaFunction_envVariables(t *testing.T) { ), }, { - Config: testAccAWSLambdaConfigEnvVariables(rName), + Config: testAccAWSLambdaConfigEnvVariables(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -84,7 +87,7 @@ func TestAccAWSLambdaFunction_envVariables(t *testing.T) { ), }, { - Config: testAccAWSLambdaConfigEnvVariablesModified(rName), + Config: testAccAWSLambdaConfigEnvVariablesModified(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -94,7 +97,7 @@ func TestAccAWSLambdaFunction_envVariables(t *testing.T) { ), }, { - Config: testAccAWSLambdaConfigEnvVariablesModifiedWithoutEnvironment(rName), + Config: testAccAWSLambdaConfigEnvVariablesModifiedWithoutEnvironment(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -110,7 +113,8 @@ func TestAccAWSLambdaFunction_envVariables(t *testing.T) { func TestAccAWSLambdaFunction_encryptedEnvVariables(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) keyRegex := regexp.MustCompile("^arn:aws:kms:") resource.Test(t, resource.TestCase{ @@ -119,7 +123,7 @@ func TestAccAWSLambdaFunction_encryptedEnvVariables(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigEncryptedEnvVariables(rName), + Config: testAccAWSLambdaConfigEncryptedEnvVariables(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -129,7 +133,7 @@ func TestAccAWSLambdaFunction_encryptedEnvVariables(t *testing.T) { ), }, { - Config: testAccAWSLambdaConfigEncryptedEnvVariablesModified(rName), + Config: testAccAWSLambdaConfigEncryptedEnvVariablesModified(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -145,7 +149,8 @@ func TestAccAWSLambdaFunction_encryptedEnvVariables(t *testing.T) { func TestAccAWSLambdaFunction_versioned(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -153,7 +158,7 @@ func TestAccAWSLambdaFunction_versioned(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigVersioned(rName), + Config: testAccAWSLambdaConfigVersioned(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -170,7 +175,9 @@ func TestAccAWSLambdaFunction_versioned(t *testing.T) { func TestAccAWSLambdaFunction_VPC(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -178,7 +185,7 @@ func TestAccAWSLambdaFunction_VPC(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigWithVPC(rName), + Config: testAccAWSLambdaConfigWithVPC(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -196,7 +203,8 @@ func TestAccAWSLambdaFunction_VPC(t *testing.T) { func TestAccAWSLambdaFunction_s3(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -204,7 +212,7 @@ func TestAccAWSLambdaFunction_s3(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigS3(rName), + Config: testAccAWSLambdaConfigS3(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_s3test", rName, &conf), testAccCheckAwsLambdaFunctionName(&conf, rName), @@ -408,7 +416,8 @@ func TestAccAWSLambdaFunction_s3Update_unversioned(t *testing.T) { } func TestAccAWSLambdaFunction_runtimeValidation_noRuntime(t *testing.T) { - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -416,7 +425,7 @@ func TestAccAWSLambdaFunction_runtimeValidation_noRuntime(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigNoRuntime(rName), + Config: testAccAWSLambdaConfigNoRuntime(rName, rSt), ExpectError: regexp.MustCompile(`\\"runtime\\": required field is not set`), }, }, @@ -424,7 +433,8 @@ func TestAccAWSLambdaFunction_runtimeValidation_noRuntime(t *testing.T) { } func TestAccAWSLambdaFunction_runtimeValidation_nodeJs(t *testing.T) { - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -432,7 +442,7 @@ func TestAccAWSLambdaFunction_runtimeValidation_nodeJs(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigNodeJsRuntime(rName), + Config: testAccAWSLambdaConfigNodeJsRuntime(rName, rSt), 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)), }, }, @@ -441,7 +451,8 @@ func TestAccAWSLambdaFunction_runtimeValidation_nodeJs(t *testing.T) { func TestAccAWSLambdaFunction_runtimeValidation_nodeJs43(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -449,7 +460,7 @@ func TestAccAWSLambdaFunction_runtimeValidation_nodeJs43(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigNodeJs43Runtime(rName), + Config: testAccAWSLambdaConfigNodeJs43Runtime(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "runtime", lambda.RuntimeNodejs43), @@ -461,7 +472,8 @@ func TestAccAWSLambdaFunction_runtimeValidation_nodeJs43(t *testing.T) { func TestAccAWSLambdaFunction_runtimeValidation_python27(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -469,7 +481,7 @@ func TestAccAWSLambdaFunction_runtimeValidation_python27(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigPython27Runtime(rName), + Config: testAccAWSLambdaConfigPython27Runtime(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "runtime", lambda.RuntimePython27), @@ -481,7 +493,8 @@ func TestAccAWSLambdaFunction_runtimeValidation_python27(t *testing.T) { func TestAccAWSLambdaFunction_runtimeValidation_java8(t *testing.T) { var conf lambda.GetFunctionOutput - rName := fmt.Sprintf("tf_test_%s", acctest.RandString(5)) + rSt := acctest.RandString(5) + rName := fmt.Sprintf("tf_test_%s", rSt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -489,7 +502,7 @@ func TestAccAWSLambdaFunction_runtimeValidation_java8(t *testing.T) { CheckDestroy: testAccCheckLambdaFunctionDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSLambdaConfigJava8Runtime(rName), + Config: testAccAWSLambdaConfigJava8Runtime(rName, rSt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "runtime", lambda.RuntimeJava8), @@ -637,9 +650,10 @@ func createTempFile(prefix string) (string, *os.File, error) { return pathToFile, f, nil } -const baseAccAWSLambdaConfig = ` +func baseAccAWSLambdaConfig(rst string) string { + return fmt.Sprintf(` resource "aws_iam_role_policy" "iam_policy_for_lambda" { - name = "iam_policy_for_lambda" + name = "iam_policy_for_lambda_%s" role = "${aws_iam_role.iam_for_lambda.id}" policy = <