Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default setting for aws_cloudwatch_event_target ecs_target's task_count #9773

Merged
merged 2 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws/resource_aws_cloudwatch_event_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
127 changes: 127 additions & 0 deletions aws/resource_aws_cloudwatch_event_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "events.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}

resource "aws_iam_role_policy" "test_policy" {
name = "%[1]s"
role = "${aws_iam_role.test_role.id}"

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:RunTask"
],
"Resource": [
"*"
]
}
]
}
EOF
}

resource "aws_ecs_cluster" "test" {
name = "%[1]s"
}

resource "aws_ecs_task_definition" "task" {
family = "%[1]s"
cpu = 256
memory = 512
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"

container_definitions = <<EOF
[
{
"name": "first",
"image": "service-first",
"cpu": 10,
"memory": 512,
"essential": true
}
]
EOF
}
`, rName)
}

func testAccAWSCloudWatchEventTargetConfigBatch(rName string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_rule" "cloudwatch_event_rule" {
Expand Down