diff --git a/builtin/providers/aws/resource_aws_cloudwatch_log_group_test.go b/builtin/providers/aws/resource_aws_cloudwatch_log_group_test.go index ca66dc25f..5c59f8499 100644 --- a/builtin/providers/aws/resource_aws_cloudwatch_log_group_test.go +++ b/builtin/providers/aws/resource_aws_cloudwatch_log_group_test.go @@ -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) } diff --git a/builtin/providers/aws/resource_aws_cloudwatch_log_metric_filter_test.go b/builtin/providers/aws/resource_aws_cloudwatch_log_metric_filter_test.go index 27de163ec..d34ea8dd0 100644 --- a/builtin/providers/aws/resource_aws_cloudwatch_log_metric_filter_test.go +++ b/builtin/providers/aws/resource_aws_cloudwatch_log_metric_filter_test.go @@ -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 = <