Skip to content

Commit

Permalink
resource/lambda_function: update acceptance test for vpc_config
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei.wang committed Feb 21, 2018
1 parent bb822e5 commit 8142c58
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion aws/import_aws_lambda_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestAccAWSLambdaFunction_importLocalFile_VPC(t *testing.T) {
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSLambdaConfigWithVPC(funcName, policyName, roleName, sgName),
Config: testAccAWSLambdaConfigWithVpc(funcName, policyName, roleName, sgName),
},

resource.TestStep{
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Send Update Lambda Function Configuration request: %#v", configReq)

err := resource.Retry(10*time.Minute, func() *resource.RetryError {
resp, err := conn.UpdateFunctionConfiguration(configReq)
_, err := conn.UpdateFunctionConfiguration(configReq)
if err != nil {
log.Printf("[DEBUG] Received error modifying Lambda Function Configuration %s: %s", d.Id(), err)

Expand Down
37 changes: 28 additions & 9 deletions aws/resource_aws_lambda_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func TestAccAWSLambdaFunction_VPC(t *testing.T) {
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigWithVPC(funcName, policyName, roleName, sgName),
Config: testAccAWSLambdaConfigWithVpc(funcName, policyName, roleName, sgName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf),
testAccCheckAwsLambdaFunctionName(&conf, funcName),
Expand All @@ -463,7 +463,7 @@ func TestAccAWSLambdaFunction_VPC(t *testing.T) {
})
}

func TestAccAWSLambdaFunction_VPCUpdate(t *testing.T) {
func TestAccAWSLambdaFunction_VpcChange(t *testing.T) {
var conf lambda.GetFunctionOutput

rString := acctest.RandString(8)
Expand All @@ -479,7 +479,7 @@ func TestAccAWSLambdaFunction_VPCUpdate(t *testing.T) {
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigWithVPC(funcName, policyName, roleName, sgName),
Config: testAccAWSLambdaConfigWithVpc(funcName, policyName, roleName, sgName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf),
testAccCheckAwsLambdaFunctionName(&conf, funcName),
Expand All @@ -491,7 +491,7 @@ func TestAccAWSLambdaFunction_VPCUpdate(t *testing.T) {
),
},
{
Config: testAccAWSLambdaConfigWithVPCUpdated(funcName, policyName, roleName, sgName, sgName2),
Config: testAccAWSLambdaConfigWithVpcUpdated(funcName, policyName, roleName, sgName, sgName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf),
testAccCheckAwsLambdaFunctionName(&conf, funcName),
Expand All @@ -502,6 +502,16 @@ func TestAccAWSLambdaFunction_VPCUpdate(t *testing.T) {
resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.0.security_group_ids.#", "2"),
),
},
{
Config: testAccAWSLambdaConfigWithVpcRemoved(funcName, policyName, roleName, sgName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf),
testAccCheckAwsLambdaFunctionName(&conf, funcName),
testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+funcName),
testAccCheckAWSLambdaFunctionVersion(&conf, "$LATEST"),
resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.#", "0"),
),
},
},
})
}
Expand All @@ -523,7 +533,7 @@ func TestAccAWSLambdaFunction_VPC_withInvocation(t *testing.T) {
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigWithVPC(funcName, policyName, roleName, sgName),
Config: testAccAWSLambdaConfigWithVpc(funcName, policyName, roleName, sgName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", funcName, &conf),
testAccAwsInvokeLambdaFunction(&conf),
Expand Down Expand Up @@ -1497,7 +1507,7 @@ resource "aws_lambda_function" "lambda_function_test" {
`, funcName)
}

func testAccAWSLambdaConfigWithVPC(funcName, policyName, roleName, sgName string) string {
func testAccAWSLambdaConfigWithVpc(funcName, policyName, roleName, sgName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+`
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
Expand All @@ -1513,7 +1523,7 @@ resource "aws_lambda_function" "lambda_function_test" {
}`, funcName)
}

func testAccAWSLambdaConfigWithVPCUpdated(funcName, policyName, roleName, sgName, sgName2 string) string {
func testAccAWSLambdaConfigWithVpcUpdated(funcName, policyName, roleName, sgName, sgName2 string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+`
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
Expand Down Expand Up @@ -1556,11 +1566,20 @@ resource "aws_security_group" "sg_for_lambda_2" {
cidr_blocks = ["0.0.0.0/0"]
}
}
`, funcName, sgName2)
}

func testAccAWSLambdaConfigWithVpcRemoved(funcName, policyName, roleName, sgName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+`
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"
}`, funcName)
}

func testAccAWSLambdaConfigS3(bucketName, roleName, funcName string) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "lambda_bucket" {
Expand Down

0 comments on commit 8142c58

Please sign in to comment.