Hey team, I've integrated infracost with my Terraf...
# help
b
Hey team, I've integrated infracost with my Terraform CICD and tried creating plan for ECS service. In my TF code, I'm referring to in-house ECS module where we have maintained ECS service in separate stack, ECS Task definition in a separate stack. But, during infracost calculation, i'm getting 0$ for ECS service.
Copy code
module.test-service[0].aws_ecs_service.this
  $0.00

+ module.test-service.aws_ecs_service.this
  $0.00
Can someone let me know what might be the reason for this?
m
what is the launch type for this service?
b
It's Linux
ARM
processor .. I'm trying to create ECS fargate @mysterious-teacher-68276
m
> ECS Task definition in a separate stack. If the stack creation/plan happening in the same terraform run or are they separate projects? If it is the latter then this is unfortunately something that infracost cannot support. For this resource infracost requires the task definition configuration to actually be part of the run so that we can infer the service constraints. If you are simply just passing an ARN from a separate stack run infracost will not be able to estimate this as it does not have access to your cloud environment.
b
If the stack creation/plan happening in the same terraform run or are they separate projects?
- So when I raise a PR, 1st plan generation will happen. Next, we will review the plan and if things are good, I will merge the PR and then apply run will happen. Cost calculation for other resources are
working fine
in this approach.
task definition configuration to actually be part of the run so that we can infer the service constraints.
- Task definition is also part of the same terraform run but it is not part of ECS module actually. Like you mentioned, we are passing
it's arn
in service module.
m
can you post the relevant parts of how this ARN is passed. Please note, if at any point this is using a
data
block this will not work with infracost. Again because of the requirement of access to your cloud environment.
s
Hi @bright-toddler-17549, I had the same problem last month. I even posted about it here. I use ECS Fargate in my environment with a in-house module and the calculation of my ECS stopped working. Other resources in the same project are calculated without any issues.
Copy code
resource "aws_ecs_service" "ecs_service_create" {
  name            = local.service-name
  cluster         = local.ecs_cluster
  task_definition = data.aws_ecs_task_definition.get_latest_task_version.arn // ALSO TESTED: aws_ecs_task_definition.task_definitions_create.arn
  desired_count   =  var.desired_count
...
...
}
I have always used
data
to get the ARN of the task, and it has always worked. But as Hugo suggested, I also tried calling the resource directly since it is in the same Terraform. Even so, the cost is not calculated. I use
data
to always get the latest version of the task. Sometimes the developers do manual tests and generate new tasks outside of Terraform. So, Terraform always uses data to list the latest version of the task to configure in the service. This was not a problem for calculating ECS costs until a few months ago.