From 7e23340f3a579a709ddeaf3ce5f0361c61548a0a Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Tue, 31 Jan 2017 12:06:06 -0500 Subject: [PATCH] provider/aws: Fix Cloudwatch Log acceptance tests Fixes `aws_cloudwatch_log_group` and `aws_cloudwatch_log_metric_filter` acceptance tests ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCloudWatchLogMetricFilter_basic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/01/31 12:01:05 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCloudWatchLogMetricFilter_basic -timeout 120m === RUN TestAccAWSCloudWatchLogMetricFilter_basic --- PASS: TestAccAWSCloudWatchLogMetricFilter_basic (27.36s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 27.390s ``` ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCloudWatchLogGroup_multiple' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/01/31 12:03:18 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCloudWatchLogGroup_multiple -timeout 120m === RUN TestAccAWSCloudWatchLogGroup_multiple --- PASS: TestAccAWSCloudWatchLogGroup_multiple (16.39s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 16.422s ``` --- .../resource_aws_cloudwatch_log_group_test.go | 2 +- ...e_aws_cloudwatch_log_metric_filter_test.go | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) 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 = <