provider/aws: Reformat and detect drift for Lambda VPC, environment
This commit is contained in:
parent
ab9059564c
commit
dede6f7302
|
@ -323,15 +323,20 @@ func resourceAwsLambdaFunctionRead(d *schema.ResourceData, meta interface{}) err
|
|||
d.Set("runtime", function.Runtime)
|
||||
d.Set("timeout", function.Timeout)
|
||||
d.Set("kms_key_arn", function.KMSKeyArn)
|
||||
if config := flattenLambdaVpcConfigResponse(function.VpcConfig); len(config) > 0 {
|
||||
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)
|
||||
}
|
||||
|
||||
config := flattenLambdaVpcConfigResponse(function.VpcConfig)
|
||||
log.Printf("[INFO] Setting Lambda %s VPC config %#v from API", d.Id(), config)
|
||||
vpcSetErr := d.Set("vpc_config", config)
|
||||
if vpcSetErr != nil {
|
||||
return fmt.Errorf("Failed setting vpc_config: %s", vpcSetErr)
|
||||
}
|
||||
|
||||
d.Set("source_code_hash", function.CodeSha256)
|
||||
|
||||
if err := d.Set("environment", flattenLambdaEnvironment(function.Environment.Variables)); err != nil {
|
||||
log.Printf("[ERR] Error setting environment for Lambda Function (%s): %s", d.Id(), err)
|
||||
}
|
||||
|
||||
// List is sorted from oldest to latest
|
||||
// so this may get costly over time :'(
|
||||
var lastVersion, lastQualifiedArn string
|
||||
|
|
|
@ -950,6 +950,19 @@ func flattenDSVpcSettings(
|
|||
return []map[string]interface{}{settings}
|
||||
}
|
||||
|
||||
func flattenLambdaEnvironment(variables map[string]*string) []interface{} {
|
||||
envs := make(map[string]interface{})
|
||||
en := make(map[string]string)
|
||||
for k, v := range variables {
|
||||
en[k] = *v
|
||||
}
|
||||
if len(en) > 0 {
|
||||
envs["variables"] = en
|
||||
}
|
||||
|
||||
return []interface{}{envs}
|
||||
}
|
||||
|
||||
func flattenLambdaVpcConfigResponse(s *lambda.VpcConfigResponse) []map[string]interface{} {
|
||||
settings := make(map[string]interface{}, 0)
|
||||
|
||||
|
@ -957,7 +970,11 @@ func flattenLambdaVpcConfigResponse(s *lambda.VpcConfigResponse) []map[string]in
|
|||
return nil
|
||||
}
|
||||
|
||||
if len(s.SubnetIds) == 0 && len(s.SecurityGroupIds) == 0 && s.VpcId == nil {
|
||||
var emptyVpc bool
|
||||
if s.VpcId == nil || *s.VpcId == "" {
|
||||
emptyVpc = true
|
||||
}
|
||||
if len(s.SubnetIds) == 0 && len(s.SecurityGroupIds) == 0 && emptyVpc {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue