diff --git a/aws/resource_aws_cloudwatch_log_subscription_filter.go b/aws/resource_aws_cloudwatch_log_subscription_filter.go index fa6985d57d5..1a33523ddd0 100644 --- a/aws/resource_aws_cloudwatch_log_subscription_filter.go +++ b/aws/resource_aws_cloudwatch_log_subscription_filter.go @@ -54,6 +54,13 @@ func resourceAwsCloudwatchLogSubscriptionFilter() *schema.Resource { "distribution": { Type: schema.TypeString, Optional: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // Ignore unsetting default value + if old == "ByLogStream" && new == "" { + return true + } + return false + }, }, }, } diff --git a/aws/resource_aws_cloudwatch_log_subscription_filter_test.go b/aws/resource_aws_cloudwatch_log_subscription_filter_test.go index 194ded578c5..ce1c1aeb7ec 100644 --- a/aws/resource_aws_cloudwatch_log_subscription_filter_test.go +++ b/aws/resource_aws_cloudwatch_log_subscription_filter_test.go @@ -35,6 +35,18 @@ func TestAccAWSCloudwatchLogSubscriptionFilter_basic(t *testing.T) { "aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", "distribution", "Random"), ), }, + { + Config: testAccAWSCloudwatchLogSubscriptionFilterConfigUnsetDistribution(rstring), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsCloudwatchLogSubscriptionFilterExists("aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", &filter, rstring), + resource.TestCheckResourceAttr( + "aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", "filter_pattern", "logtype test"), + resource.TestCheckResourceAttr( + "aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", "name", fmt.Sprintf("test_lambdafunction_logfilter_%s", rstring)), + resource.TestCheckResourceAttr( + "aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", "log_group_name", fmt.Sprintf("example_lambda_name_%s", rstring)), + ), + }, { ResourceName: "aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", ImportState: true, @@ -266,3 +278,77 @@ EOF } `, rstring, rstring, rstring, rstring, rstring) } + +func testAccAWSCloudwatchLogSubscriptionFilterConfigUnsetDistribution(rstring string) string { + return fmt.Sprintf(` +resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" { + name = "test_lambdafunction_logfilter_%s" + log_group_name = "${aws_cloudwatch_log_group.logs.name}" + filter_pattern = "logtype test" + destination_arn = "${aws_lambda_function.test_lambdafunction.arn}" +} + +resource "aws_lambda_function" "test_lambdafunction" { + filename = "test-fixtures/lambdatest.zip" + function_name = "example_lambda_name_%s" + role = "${aws_iam_role.iam_for_lambda.arn}" + runtime = "nodejs8.10" + handler = "exports.handler" +} + +resource "aws_cloudwatch_log_group" "logs" { + name = "example_lambda_name_%s" + retention_in_days = 1 +} + +resource "aws_lambda_permission" "allow_cloudwatch_logs" { + statement_id = "AllowExecutionFromCloudWatchLogs" + action = "lambda:*" + function_name = "${aws_lambda_function.test_lambdafunction.arn}" + principal = "logs.amazonaws.com" +} + +resource "aws_iam_role" "iam_for_lambda" { + name = "test_lambdafuntion_iam_role_%s" + + assume_role_policy = <