Skip to content

Commit

Permalink
resource/aws_cloudwatch_log_subscription_filter: Add support for dist…
Browse files Browse the repository at this point in the history
…ribution (#3046)

* adding support for distribution in cw subscription filters. resolves #2853

* Update resource_aws_cloudwatch_log_subscription_filter_test.go
  • Loading branch information
ryandeivert authored and Ninir committed Jan 25, 2018
1 parent 41a383b commit c244839
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aws/resource_aws_cloudwatch_log_subscription_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func resourceAwsCloudwatchLogSubscriptionFilter() *schema.Resource {
Optional: true,
Computed: true,
},
"distribution": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -121,6 +125,10 @@ func getAwsCloudWatchLogsSubscriptionFilterInput(d *schema.ResourceData) cloudwa
params.RoleArn = aws.String(d.Get("role_arn").(string))
}

if _, ok := d.GetOk("distribution"); ok {
params.Distribution = aws.String(d.Get("distribution").(string))
}

return params
}

Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_cloudwatch_log_subscription_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func TestAccAWSCloudwatchLogSubscriptionFilter_basic(t *testing.T) {
"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)),
resource.TestCheckResourceAttr(
"aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", "distribution", "Random"),
),
},
},
Expand Down Expand Up @@ -152,6 +154,7 @@ resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter
log_group_name = "${aws_cloudwatch_log_group.logs.name}"
filter_pattern = "logtype test"
destination_arn = "${aws_lambda_function.test_lambdafunction.arn}"
distribution = "Random"
}
resource "aws_lambda_function" "test_lambdafunction" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter
log_group_name = "/aws/lambda/example_lambda_name"
filter_pattern = "logtype test"
destination_arn = "${aws_kinesis_stream.test_logstream.arn}"
distribution = "Random"
}
```

Expand All @@ -31,6 +32,7 @@ The following arguments are supported:
* `filter_pattern` - (Required) A valid CloudWatch Logs filter pattern for subscribing to a filtered stream of log events.
* `log_group_name` - (Required) The name of the log group to associate the subscription filter with
* `role_arn` - (Optional) The ARN of an IAM role that grants Amazon CloudWatch Logs permissions to deliver ingested log events to the destination. If you use Lambda as a destination, you should skip this argument and use `aws_lambda_permission` resource for granting access from CloudWatch logs to the destination Lambda function.
* `distribution` - (Optional) The method used to distribute log data to the destination. By default log data is grouped by log stream, but the grouping can be set to random for a more even distribution. This property is only applicable when the destination is an Amazon Kinesis stream. Valid values are "Random" and "ByLogStream".

## Attributes Reference

Expand Down

0 comments on commit c244839

Please sign in to comment.