diff --git a/aws/resource_aws_lambda_alias.go b/aws/resource_aws_lambda_alias.go index 40ce9ebd5ef..50ec672a2c6 100644 --- a/aws/resource_aws_lambda_alias.go +++ b/aws/resource_aws_lambda_alias.go @@ -30,6 +30,13 @@ func resourceAwsLambdaAlias() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // Using function name or ARN should not be shown as a diff. + // Try to convert the old and new values from ARN to function name + oldFunctionName, oldFunctionNameErr := getFunctionNameFromLambdaArn(old) + newFunctionName, newFunctionNameErr := getFunctionNameFromLambdaArn(new) + return (oldFunctionName == new && oldFunctionNameErr == nil) || (newFunctionName == old && newFunctionNameErr == nil) + }, }, "function_version": { Type: schema.TypeString, diff --git a/aws/resource_aws_lambda_alias_test.go b/aws/resource_aws_lambda_alias_test.go index 92a1bfc4592..5b857c5b2bc 100644 --- a/aws/resource_aws_lambda_alias_test.go +++ b/aws/resource_aws_lambda_alias_test.go @@ -44,6 +44,10 @@ func TestAccAWSLambdaAlias_basic(t *testing.T) { ImportStateId: fmt.Sprintf("%s/%s", funcName, aliasName), ImportStateVerify: true, }, + { + Config: testAccAwsLambdaAliasConfigUsingFunctionName(roleName, policyName, attachmentName, funcName, aliasName), + PlanOnly: true, + }, }, }) } @@ -219,8 +223,7 @@ func testAccCheckAwsLambdaAliasRoutingConfigDoesNotExist(mapping *lambda.AliasCo return nil } } - -func testAccAwsLambdaAliasConfig(roleName, policyName, attachmentName, funcName, aliasName string) string { +func testAccAwsLambdaAliasBaseConfig(roleName, policyName, attachmentName string) string { return fmt.Sprintf(` resource "aws_iam_role" "iam_for_lambda" { name = "%s" @@ -268,7 +271,13 @@ resource "aws_iam_policy_attachment" "policy_attachment_for_role" { roles = ["${aws_iam_role.iam_for_lambda.name}"] policy_arn = "${aws_iam_policy.policy_for_role.arn}" } +`, roleName, policyName, attachmentName) +} +func testAccAwsLambdaAliasConfig(roleName, policyName, attachmentName, funcName, aliasName string) string { + return composeConfig( + testAccAwsLambdaAliasBaseConfig(roleName, policyName, attachmentName), + fmt.Sprintf(` resource "aws_lambda_function" "lambda_function_test_create" { filename = "test-fixtures/lambdatest.zip" function_name = "%s" @@ -285,58 +294,36 @@ resource "aws_lambda_alias" "lambda_alias_test" { function_name = "${aws_lambda_function.lambda_function_test_create.arn}" function_version = "1" } -`, roleName, policyName, attachmentName, funcName, aliasName) +`, funcName, aliasName)) } -func testAccAwsLambdaAliasConfigWithRoutingConfig(roleName, policyName, attachmentName, funcName, aliasName string) string { - return fmt.Sprintf(` -resource "aws_iam_role" "iam_for_lambda" { - name = "%s" - - assume_role_policy = <