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

aws_ecs_service.launch_type can be optional #12566

Open
asans opened this issue Mar 28, 2020 · 4 comments
Open

aws_ecs_service.launch_type can be optional #12566

asans opened this issue Mar 28, 2020 · 4 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ecs Issues and PRs that pertain to the ecs service.

Comments

@asans
Copy link

asans commented Mar 28, 2020

With the introduction of capacity providers, launch_type is not required and can be omitted.

See AWS Docs here:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_definition_parameters.html

Primarily, here is the blurb:

  • If launch_type is specified, then capacity_provider_strategy must be omitted.
  • If capacity_provider_strategy is specified, then launch_type must be omitted.
  • If no capacity_provider_strategy or launch_type is specified, the defaultCapacityProviderStrategy for the cluster is used.

The issue is with the last point. If both launch_type and capacity_provider_strategy is not specified in Terraform, then terraform defaults the launch_type to "EC2". This then causes the capacity provider strategy not to be used or defaulted to the cluster strategy.

So the fix should just be to make the launch_type optional per the AWS service parameter definition and should NOT default to "EC2" when not specified, but rather just omitted when not specified.

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 Version

Terraform v0.12.20

Affected Resource(s)

  • aws_ecs_service
@ghost ghost added the service/ecs Issues and PRs that pertain to the ecs service. label Mar 28, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 28, 2020
@breathingdust breathingdust added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 22, 2021
@tkrafael
Copy link

tkrafael commented Mar 8, 2022

Also it would be good if it was possible to pass a default value in launch_type. I have following issue:
I have a module that allows dynamic capacity provider as well as launch_type variables.
When I try to omit lauch_type, it won't work as I cannot pass null, empty anything other than "EC2", "FARGATE" or "EXTERNAL".
However, if I pass one of those words AND try to add a capacity provider strategy, I get an error saying I cannot set launch_type and capacity provider together.

Eg:

# assume this is a git module
resource aws_ecs_service this {
  launch_type         = var.launch_type
  dynamic capacity_provider_strategy {
    for_each = toset(var.capacity_provider_strategies)
    content {
      capacity_provider = capacity_provider_strategy.value.capacity_provider
      weight = capacity_provider_strategy.value.weight
      base = capacity_provider_strategy.value.base
    }
  }
# other configuration omitted
}

Terragrunt usage:

terraform {
   # assume it is a git repo
    source = "${include.root.inputs.repo_base}/modules/ecs-anywhere/ecs-service"
}

inputs = {
    service_name = "my"
    task_definition = "myt"
    launch_type = "" # this is part of the problem
    scheduling_strategy = "REPLICA"
    capacity_provider_strategies = [{
        capacity_provider = "FARGATE_SPOT"
        weight = 4
        base = 0
    },
    {
        capacity_provider = "FARGATE"
        weight = 1
        base = 1
    }]
}

@DenisBY
Copy link

DenisBY commented Oct 21, 2022

Do you have any update on this? We have more than 50 services in one cluster with the default_capacity_provider set to FARGATE_SPOT and it would be nice to use default cluster value instead of specifying it for every service.

@DenisBY
Copy link

DenisBY commented Oct 21, 2022

I see it's already fixed. Or I'm looking at the wrong place?
https://github.com/hashicorp/terraform-provider-aws/blob/v4.36.0/internal/service/ecs/service.go#L178

UPDATE:

Ok, I got it. It's optional but default value is EC2. But it should be 'not set'.

@tkrafael
Copy link

There's another problem. Setting launch type to null causes a validation error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
Development

No branches or pull requests

4 participants