Merge pull request #6157 from TimeIncOSS/b-lambda-vpc-read

provider/aws: Fix Lambda VPC integration (missing vpc_id field)
This commit is contained in:
Radek Simko 2016-04-13 15:19:20 +01:00
commit 269858998d
2 changed files with 14 additions and 1 deletions

View File

@ -98,6 +98,10 @@ func resourceAwsLambdaFunction() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString, 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("runtime", function.Runtime)
d.Set("timeout", function.Timeout) d.Set("timeout", function.Timeout)
if config := flattenLambdaVpcConfigResponse(function.VpcConfig); len(config) > 0 { 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) d.Set("source_code_hash", function.CodeSha256)

View File

@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"testing" "testing"
@ -51,6 +52,10 @@ func TestAccAWSLambdaFunction_VPC(t *testing.T) {
testAccCheckAwsLambdaFunctionName(&conf, "example_lambda_name"), testAccCheckAwsLambdaFunctionName(&conf, "example_lambda_name"),
testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":example_lambda_name"), testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":example_lambda_name"),
testAccCheckAWSLambdaFunctionVersion(&conf, "$LATEST"), 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-")),
), ),
}, },
}, },