From 4c64477a65b19844f9bbc1248d3c0686fb27c0cc Mon Sep 17 00:00:00 2001 From: Dave D'Amico Date: Mon, 8 Jul 2019 08:17:58 -0400 Subject: [PATCH 1/3] initial commit --- aws/resource_aws_cloudwatch_log_subscription_filter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_cloudwatch_log_subscription_filter.go b/aws/resource_aws_cloudwatch_log_subscription_filter.go index fa6985d57d5..49584b69385 100644 --- a/aws/resource_aws_cloudwatch_log_subscription_filter.go +++ b/aws/resource_aws_cloudwatch_log_subscription_filter.go @@ -54,6 +54,7 @@ func resourceAwsCloudwatchLogSubscriptionFilter() *schema.Resource { "distribution": { Type: schema.TypeString, Optional: true, + Computed: true, }, }, } From cbfecbac5fb5a0325d79c9151f83d2327fe30717 Mon Sep 17 00:00:00 2001 From: DaveD Date: Tue, 9 Jul 2019 20:10:00 -0400 Subject: [PATCH 2/3] changes based on feedback: DiffSuppresFunc instead of Computed + Updated Acceptance test --- ..._aws_cloudwatch_log_subscription_filter.go | 8 +- ...cloudwatch_log_subscription_filter_test.go | 86 +++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_cloudwatch_log_subscription_filter.go b/aws/resource_aws_cloudwatch_log_subscription_filter.go index 49584b69385..1a33523ddd0 100644 --- a/aws/resource_aws_cloudwatch_log_subscription_filter.go +++ b/aws/resource_aws_cloudwatch_log_subscription_filter.go @@ -54,7 +54,13 @@ func resourceAwsCloudwatchLogSubscriptionFilter() *schema.Resource { "distribution": { Type: schema.TypeString, Optional: true, - Computed: 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..17adf5d935f 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 = < Date: Tue, 9 Jul 2019 20:17:40 -0400 Subject: [PATCH 3/3] go fmt --- aws/resource_aws_cloudwatch_log_subscription_filter_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_cloudwatch_log_subscription_filter_test.go b/aws/resource_aws_cloudwatch_log_subscription_filter_test.go index 17adf5d935f..ce1c1aeb7ec 100644 --- a/aws/resource_aws_cloudwatch_log_subscription_filter_test.go +++ b/aws/resource_aws_cloudwatch_log_subscription_filter_test.go @@ -44,7 +44,7 @@ func TestAccAWSCloudwatchLogSubscriptionFilter_basic(t *testing.T) { 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)), + "aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", "log_group_name", fmt.Sprintf("example_lambda_name_%s", rstring)), ), }, {