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..02ab7a85a4e 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 = "%[1]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 = "%[1]s" + + assume_role_policy = <