Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_lambda_function: Added Lambda function name validation #25259

Merged
merged 4 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/25259.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_lambda_function: Add validation for `function_name` attribute
```
7 changes: 4 additions & 3 deletions internal/service/lambda/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ func ResourceFunction() *schema.Resource {
},
},
"function_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validFunctionName(),
},
"handler": {
Type: schema.TypeString,
Expand Down
21 changes: 21 additions & 0 deletions internal/service/lambda/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,27 @@ func TestAccLambdaFunction_encryptedEnvVariables(t *testing.T) {
})
}

func TestAccLambdaFunction_nameValidation(t *testing.T) {
rString := sdkacctest.RandString(8)
badFuncName := "prefix.viewer_request_lambda"
policyName := fmt.Sprintf("tf_acc_policy_lambda_func_basic_%s", rString)
roleName := fmt.Sprintf("tf_acc_role_lambda_func_basic_%s", rString)
sgName := fmt.Sprintf("tf_acc_sg_lambda_func_basic_%s", rString)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccFunctionConfig_basic(badFuncName, policyName, roleName, sgName),
ExpectError: regexp.MustCompile(`invalid value for function_name \(must be valid function name or function ARN\)`),
},
},
})
}

func TestAccLambdaFunction_versioned(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
Expand Down