From 86e33fe91d5163ff59c5457e1b1113dc4c5dad04 Mon Sep 17 00:00:00 2001 From: Audrey Eschright Date: Wed, 14 Aug 2019 15:23:05 -0700 Subject: [PATCH 1/2] Add default setting for aws_cloudwatch_event_target ecs_target's task_count. --- aws/resource_aws_cloudwatch_event_target.go | 1 + ...source_aws_cloudwatch_event_target_test.go | 127 ++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/aws/resource_aws_cloudwatch_event_target.go b/aws/resource_aws_cloudwatch_event_target.go index ddd44846418..dcbda53dd62 100644 --- a/aws/resource_aws_cloudwatch_event_target.go +++ b/aws/resource_aws_cloudwatch_event_target.go @@ -138,6 +138,7 @@ func resourceAwsCloudWatchEventTarget() *schema.Resource { Type: schema.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(1, math.MaxInt32), + Default: 1, }, "task_definition_arn": { Type: schema.TypeString, diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index 422de8d158f..b47c8807571 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -247,6 +247,32 @@ func TestAccAWSCloudWatchEventTarget_ecs(t *testing.T) { }) } +func TestAccAWSCloudWatchEventTarget_ecsWithBlankTaskCount(t *testing.T) { + var target events.Target + rName := acctest.RandomWithPrefix("tf_ecs_target") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCloudWatchEventTargetConfigEcsWithBlankTaskCount(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudWatchEventTargetExists("aws_cloudwatch_event_target.test", &target), + resource.TestCheckResourceAttr("aws_cloudwatch_event_target.test", "ecs_target.0.task_count", "1"), + ), + }, + { + ResourceName: "aws_cloudwatch_event_target.test", + ImportState: true, + ImportStateIdFunc: testAccAWSCloudWatchEventTargetImportStateIdFunc("aws_cloudwatch_event_target.test"), + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSCloudWatchEventTarget_batch(t *testing.T) { var target events.Target rName := acctest.RandomWithPrefix("tf_batch_target") @@ -698,6 +724,107 @@ EOF `, rName, rName, rName, rName, rName) } +func testAccAWSCloudWatchEventTargetConfigEcsWithBlankTaskCount(rName string) string { + return fmt.Sprintf(` +resource "aws_cloudwatch_event_rule" "schedule" { + name = "%s" + description = "schedule_ecs_test" + + schedule_expression = "rate(5 minutes)" +} + +resource "aws_vpc" "vpc" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_subnet" "subnet" { + vpc_id = "${aws_vpc.vpc.id}" + cidr_block = "10.1.1.0/24" +} + +resource "aws_cloudwatch_event_target" "test" { + arn = "${aws_ecs_cluster.test.id}" + rule = "${aws_cloudwatch_event_rule.schedule.id}" + role_arn = "${aws_iam_role.test_role.arn}" + + ecs_target { + task_definition_arn = "${aws_ecs_task_definition.task.arn}" + launch_type = "FARGATE" + + network_configuration { + subnets = ["${aws_subnet.subnet.id}"] + } + } +} + +resource "aws_iam_role" "test_role" { + name = "%s" + + assume_role_policy = < Date: Wed, 21 Aug 2019 17:37:21 -0700 Subject: [PATCH 2/2] Clean up test config --- aws/resource_aws_cloudwatch_event_target_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index b47c8807571..02ab7a85a4e 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -727,7 +727,7 @@ EOF func testAccAWSCloudWatchEventTargetConfigEcsWithBlankTaskCount(rName string) string { return fmt.Sprintf(` resource "aws_cloudwatch_event_rule" "schedule" { - name = "%s" + name = "%[1]s" description = "schedule_ecs_test" schedule_expression = "rate(5 minutes)" @@ -758,7 +758,7 @@ resource "aws_cloudwatch_event_target" "test" { } resource "aws_iam_role" "test_role" { - name = "%s" + name = "%[1]s" assume_role_policy = <