Skip to content

Commit e476b44

Browse files
authored
Merge pull request #25259 from daftkid/f-add_lambda_name_validation
r/aws_lambda_function: Added Lambda function name validation
2 parents 0433b0e + 1c7ea35 commit e476b44

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.changelog/25259.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_lambda_function: Add validation for `function_name` attribute
3+
```

internal/service/lambda/function.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ func ResourceFunction() *schema.Resource {
186186
},
187187
},
188188
"function_name": {
189-
Type: schema.TypeString,
190-
Required: true,
191-
ForceNew: true,
189+
Type: schema.TypeString,
190+
Required: true,
191+
ForceNew: true,
192+
ValidateFunc: validFunctionName(),
192193
},
193194
"handler": {
194195
Type: schema.TypeString,

internal/service/lambda/function_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,27 @@ func TestAccLambdaFunction_encryptedEnvVariables(t *testing.T) {
510510
})
511511
}
512512

513+
func TestAccLambdaFunction_nameValidation(t *testing.T) {
514+
rString := sdkacctest.RandString(8)
515+
badFuncName := "prefix.viewer_request_lambda"
516+
policyName := fmt.Sprintf("tf_acc_policy_lambda_func_basic_%s", rString)
517+
roleName := fmt.Sprintf("tf_acc_role_lambda_func_basic_%s", rString)
518+
sgName := fmt.Sprintf("tf_acc_sg_lambda_func_basic_%s", rString)
519+
520+
resource.ParallelTest(t, resource.TestCase{
521+
PreCheck: func() { acctest.PreCheck(t) },
522+
ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID),
523+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
524+
CheckDestroy: testAccCheckFunctionDestroy,
525+
Steps: []resource.TestStep{
526+
{
527+
Config: testAccFunctionConfig_basic(badFuncName, policyName, roleName, sgName),
528+
ExpectError: regexp.MustCompile(`invalid value for function_name \(must be valid function name or function ARN\)`),
529+
},
530+
},
531+
})
532+
}
533+
513534
func TestAccLambdaFunction_versioned(t *testing.T) {
514535
if testing.Short() {
515536
t.Skip("skipping long-running test in short mode")

0 commit comments

Comments
 (0)