Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #8230 #9265

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions aws/resource_aws_cloudwatch_log_subscription_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
},
}
Expand Down
86 changes: 86 additions & 0 deletions aws/resource_aws_cloudwatch_log_subscription_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}

resource "aws_iam_role_policy" "test_lambdafunction_iam_policy" {
name = "test_lambdafunction_iam_policy_%s"
role = "${aws_iam_role.iam_for_lambda.id}"

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1441111030000",
"Effect": "Allow",
"Action": [
"lambda:*"
],
"Resource": [
"*"
]
}
]
}
EOF
}
`, rstring, rstring, rstring, rstring, rstring)
}