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

resource/aws_cloudwatch_event_target: ecs_target's launch_type should not have a default #16078

Closed
ianneub opened this issue Nov 7, 2020 · 7 comments · Fixed by #22803
Closed
Assignees
Labels
breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. bug Addresses a defect in current functionality.
Milestone

Comments

@ianneub
Copy link
Contributor

ianneub commented Nov 7, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/aws v3.14.1

Affected Resource(s)

  • aws_cloudwatch_event_target

Terraform Configuration Files

resource "aws_ecs_cluster" "database" {
  name = "database"
}

resource "aws_cloudwatch_event_rule" "db_backup" {
  name                = "DBBackup"
  description         = "Run daily at 07:05 UTC"
  schedule_expression = "cron(5 7 * * ? *)"
}

resource "aws_cloudwatch_event_target" "dump_database" {
  arn       = aws_ecs_cluster.database.arn
  rule      = aws_cloudwatch_event_rule.db_backup.name
  role_arn  = "arn:aws:iam::696278446003:role/ecsEventsRole"

  ecs_target {
    task_count          = 1
    task_definition_arn = aws_ecs_task_definition.dump_database.arn
  }
}

resource "aws_ecs_task_definition" "dump_database" {
  family                = "service"
  container_definitions = file("task-definitions/dump_database.json")
}

task-definitions/dump_database.json:

[
  {
    "name": "first",
    "image": "service-first",
    "cpu": 10,
    "memory": 512,
    "essential": true,
    "portMappings": [
      {
        "containerPort": 80,
        "hostPort": 80
      }
    ]
  }
]

Expected Behavior

The launch_type should not be set.

Actual Behavior

In the aws_cloudwatch_event_target output, the ecs_target launch_type is set to EC2.

Steps to Reproduce

  1. terraform apply

References

@ghost ghost added service/cloudwatchevents service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/ecs Issues and PRs that pertain to the ecs service. labels Nov 7, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Nov 7, 2020
@gbataille
Copy link

gbataille commented Nov 9, 2020

Additionally, launch_type = '' should be a valid value (which I guess used to be the default)

This is critical to be able to use the capacity provider of the ECS cluster. You can have a look here

aws/containers-roadmap#937 (comment)

This is a regression. I have had this setup with launch_type = '' for a few months. I just tested, it worked fine with provider 3.13.0. The regression was introduced in 3.14.0, although the validation error is not the same in 3.14.0:

Error: InvalidParameter: 1 validation error(s) found.
- minimum field size of 1, ListTargetsByRuleInput.EventBusName.

and 3.14.1:

Error: expected ecs_target.0.launch_type to be one of [EC2 FARGATE], got 
  on dr_db.tf line 105, in resource "aws_cloudwatch_event_target" "db_dump":
 105:     launch_type         = ""

@danishgarg
Copy link

We are also facing this issue. We want to be able to run scheduled task on an ECS cluster and want to scale to 0 with termination protection on the ASG. The capacity provider is not activated when the CloudWatch event is triggered and the event fails complaining about the absence of any EC2 instances on the cluster. (aws/containers-roadmap#937). We came across the workaround that @gbataille has put in the corresponding GitHub issue (aws/containers-roadmap#937) but we are getting a terraform error
Error: expected ecs_target.0.launch_type to be one of [EC2 FARGATE], got

Can you please let us know if we can expect a fix for this issue from terraform end?

@rossini-bruno
Copy link

We had the same issue, and ended up creating a lambda python to run a task using Fargate Spot; using run_rask():

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.run_task

@ianneub
Copy link
Contributor Author

ianneub commented May 26, 2021

Bump. This appears to be the cause of the problem:
https://github.com/hashicorp/terraform-provider-aws/blame/main/aws/resource_aws_cloudwatch_event_target.go#L149

@DrFaust92 Can this be easily changed to allow an empty string?

This is blocking me from upgrading my aws provider that I now need to get access to newer settings.

@anGie44 anGie44 added bug Addresses a defect in current functionality. breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. and removed needs-triage Waiting for first response or review from a maintainer. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/ecs Issues and PRs that pertain to the ecs service. service/eventbridge labels Jun 10, 2021
@anGie44
Copy link
Contributor

anGie44 commented Jun 10, 2021

Hi @ianneub , thank you for raising this issue! Just noting here that removing the default value would be a breaking change, though the workaround you've proposed to support the empty string is a great alternative 👍

@github-actions
Copy link

This functionality has been released in v4.0.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. bug Addresses a defect in current functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants