Drop alias from state file if missing from lambda. (#10759)

* Drop alias from state file if missing from lambda.

This commit fixes an issue where if you remove a AWS Lambda, the corresponding alias for that Lambda is also deleted.

* Added missing imports.

* Removed non-local reference to constant.
This commit is contained in:
Dan Thagard 2016-12-15 16:33:38 -05:00 committed by Clint
parent 442f6de8c9
commit 82ef4b678d
1 changed files with 8 additions and 0 deletions

View File

@ -3,8 +3,10 @@ package aws
import (
"fmt"
"log"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/hashicorp/terraform/helper/schema"
)
@ -82,6 +84,12 @@ func resourceAwsLambdaAliasRead(d *schema.ResourceData, meta interface{}) error
aliasConfiguration, err := conn.GetAlias(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "ResourceNotFoundException" && strings.Contains(awsErr.Message(), "Cannot find alias arn") {
d.SetId("")
return nil
}
}
return err
}