From 3f188d5d1b4912febad101ac923dacb8383d75d2 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 13 Apr 2016 14:45:47 +0100 Subject: [PATCH 1/2] provider/aws: Improve test for VPC-based Lambda func --- builtin/providers/aws/resource_aws_lambda_function_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/aws/resource_aws_lambda_function_test.go b/builtin/providers/aws/resource_aws_lambda_function_test.go index 1530ec34a..abfc40ae8 100644 --- a/builtin/providers/aws/resource_aws_lambda_function_test.go +++ b/builtin/providers/aws/resource_aws_lambda_function_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "regexp" "strings" "testing" @@ -51,6 +52,10 @@ func TestAccAWSLambdaFunction_VPC(t *testing.T) { testAccCheckAwsLambdaFunctionName(&conf, "example_lambda_name"), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":example_lambda_name"), testAccCheckAWSLambdaFunctionVersion(&conf, "$LATEST"), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.#", "1"), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.0.subnet_ids.#", "1"), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.0.security_group_ids.#", "1"), + resource.TestMatchResourceAttr("aws_lambda_function.lambda_function_test", "vpc_config.0.vpc_id", regexp.MustCompile("^vpc-")), ), }, }, From f6a21e789954a4d9e770ba9b5378b117f3d0721a Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 13 Apr 2016 14:47:51 +0100 Subject: [PATCH 2/2] provider/aws: Read VPC ID for Lambda function back from API --- builtin/providers/aws/resource_aws_lambda_function.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_lambda_function.go b/builtin/providers/aws/resource_aws_lambda_function.go index 1c6e706b1..f54bc1a2e 100644 --- a/builtin/providers/aws/resource_aws_lambda_function.go +++ b/builtin/providers/aws/resource_aws_lambda_function.go @@ -98,6 +98,10 @@ func resourceAwsLambdaFunction() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, + "vpc_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -249,7 +253,11 @@ func resourceAwsLambdaFunctionRead(d *schema.ResourceData, meta interface{}) err d.Set("runtime", function.Runtime) d.Set("timeout", function.Timeout) if config := flattenLambdaVpcConfigResponse(function.VpcConfig); len(config) > 0 { - d.Set("vpc_config", config) + log.Printf("[INFO] Setting Lambda %s VPC config %#v from API", d.Id(), config) + err := d.Set("vpc_config", config) + if err != nil { + return fmt.Errorf("Failed setting vpc_config: %s", err) + } } d.Set("source_code_hash", function.CodeSha256)