Open asans opened 4 years ago
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
}]
}
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.
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'.
There's another problem. Setting launch type to null causes a validation error
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:
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
Terraform Version
Terraform v0.12.20
Affected Resource(s)