Merge pull request #11561 from hashicorp/b-fix-cloudwatch-log-group-acctests
provider/aws: Fix Cloudwatch Log acceptance tests
This commit is contained in:
commit
8ab661ef3c
|
@ -254,5 +254,5 @@ resource "aws_cloudwatch_log_group" "charlie" {
|
|||
name = "foo-bar-%d"
|
||||
retention_in_days = 3653
|
||||
}
|
||||
`, rInt, rInt, rInt)
|
||||
`, rInt, rInt+1, rInt+2)
|
||||
}
|
||||
|
|
|
@ -6,27 +6,29 @@ import (
|
|||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAWSCloudWatchLogMetricFilter_basic(t *testing.T) {
|
||||
var mf cloudwatchlogs.MetricFilter
|
||||
rInt := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSCloudWatchLogMetricFilterDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfig,
|
||||
{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfig(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudWatchLogMetricFilterExists("aws_cloudwatch_log_metric_filter.foobar", &mf),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", "MyAppAccessCount"),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, "MyAppAccessCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "pattern", ""),
|
||||
testAccCheckCloudWatchLogMetricFilterPattern(&mf, ""),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", "MyApp/access.log"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", fmt.Sprintf("MyApp/access-%d.log", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.name", "EventCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.namespace", "YourNamespace"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.value", "1"),
|
||||
|
@ -37,15 +39,15 @@ func TestAccAWSCloudWatchLogMetricFilter_basic(t *testing.T) {
|
|||
}),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfigModified,
|
||||
{
|
||||
Config: testAccAWSCloudWatchLogMetricFilterConfigModified(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckCloudWatchLogMetricFilterExists("aws_cloudwatch_log_metric_filter.foobar", &mf),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", "MyAppAccessCount"),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, "MyAppAccessCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "name", fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
testAccCheckCloudWatchLogMetricFilterName(&mf, fmt.Sprintf("MyAppAccessCount-%d", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "pattern", "{ $.errorCode = \"AccessDenied\" }"),
|
||||
testAccCheckCloudWatchLogMetricFilterPattern(&mf, "{ $.errorCode = \"AccessDenied\" }"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", "MyApp/access.log"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "log_group_name", fmt.Sprintf("MyApp/access-%d.log", rInt)),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.name", "AccessDeniedCount"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.namespace", "MyNamespace"),
|
||||
resource.TestCheckResourceAttr("aws_cloudwatch_log_metric_filter.foobar", "metric_transformation.0.value", "2"),
|
||||
|
@ -146,9 +148,10 @@ func testAccCheckAWSCloudWatchLogMetricFilterDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var testAccAWSCloudWatchLogMetricFilterConfig = `
|
||||
func testAccAWSCloudWatchLogMetricFilterConfig(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_cloudwatch_log_metric_filter" "foobar" {
|
||||
name = "MyAppAccessCount"
|
||||
name = "MyAppAccessCount-%d"
|
||||
pattern = ""
|
||||
log_group_name = "${aws_cloudwatch_log_group.dada.name}"
|
||||
|
||||
|
@ -160,13 +163,15 @@ resource "aws_cloudwatch_log_metric_filter" "foobar" {
|
|||
}
|
||||
|
||||
resource "aws_cloudwatch_log_group" "dada" {
|
||||
name = "MyApp/access.log"
|
||||
name = "MyApp/access-%d.log"
|
||||
}
|
||||
`, rInt, rInt)
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAWSCloudWatchLogMetricFilterConfigModified = `
|
||||
func testAccAWSCloudWatchLogMetricFilterConfigModified(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_cloudwatch_log_metric_filter" "foobar" {
|
||||
name = "MyAppAccessCount"
|
||||
name = "MyAppAccessCount-%d"
|
||||
pattern = <<PATTERN
|
||||
{ $.errorCode = "AccessDenied" }
|
||||
PATTERN
|
||||
|
@ -180,6 +185,7 @@ PATTERN
|
|||
}
|
||||
|
||||
resource "aws_cloudwatch_log_group" "dada" {
|
||||
name = "MyApp/access.log"
|
||||
name = "MyApp/access-%d.log"
|
||||
}
|
||||
`, rInt, rInt)
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue