https://infracost.io logo
#help
Title
# help
a

able-soccer-51632

01/05/2024, 6:30 PM
Hi all, can someone help with weird behavior? I'm using Terraform + Terragrunt to deploy ECS Services using Fargate. I have Terraform modules hosted in private repos, my folder structure is as follows:
Copy code
├── _global
│   └── ecs_admin_ui.hcl
├── common.hcl
├── eu-west-1
│   ├── dev
│   │   ├── ecs_admin_ui
│   │   │   └── terragrunt.hcl
│   │   └── env.hcl
│   ├── prd
│   │   ├── ecs_admin_ui
│   │   │   └── terragrunt.hcl
│   │   └── env.hcl
│   ├── region.hcl
│   └── stg
│       ├── ecs_admin_ui
│       │   └── terragrunt.hcl
│       └── env.hcl
├── terragrunt.hcl
└── us-east-1
    ├── dev
    │   ├── ecs_admin_ui
    │   │   └── terragrunt.hcl
    │   └── env.hcl
    ├── prd
    │   ├── ecs_admin_ui
    │   │   └── terragrunt.hcl
    │   └── env.hcl
    ├── region.hcl
    └── stg
        ├── ecs_admin_ui
        │   └── terragrunt.hcl
        └── env.hcl
If I change something on Fargete scope, such as increase the number of containers, nothing happens on the Infracost report, However, if I create another Service on Fargate, it identifies and shows the cost on reports. My
infracost.yaml
file using GitHub Actions to deploy:
Copy code
name: Infracost
on: [pull_request]

env:
  SSH_AUTH_SOCK: /tmp/ssh_agent.sock
  INFRACOST_LOG_LEVEL: debug

jobs:
  terraform-project:
    name: Infracost
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    env:
      TF_ROOT: terragrunt/

    steps:
      - name: add GIT_SSH_KEY
        run: |
          ssh-agent -a $SSH_AUTH_SOCK
          mkdir -p ~/.ssh
          echo "${{ secrets.TERRAFORM_MODULES_SSH_KEY }}" | tr -d '\r' | ssh-add -
          ssh-keyscan <http://github.com|github.com> >> ~/.ssh/known_hosts

      - name: Setup Infracost
        uses: infracost/actions/setup@v2
        with:
          api-key: ${{ secrets.INFRACOST_API_KEY }}

      - name: Checkout base branch
        uses: actions/checkout@v3
        with:
          ref: '${{ github.event.pull_request.base.ref }}'

      - name: Generate Infracost cost estimate baseline
        run: |
          infracost breakdown --path=${TF_ROOT} \
                              --format=json \
                              --out-file=/tmp/infracost-base.json

      - name: Checkout PR branch
        uses: actions/checkout@v3

      - name: Generate Infracost diff
        run: |
          infracost diff --path=${TF_ROOT} \
                              --format=json \
                              --compare-to=/tmp/infracost-base.json \
                              --out-file=/tmp/infracost.json
          cat /tmp/infracost.json

      - name: Post Infracost comment
        run: |
          infracost comment github --path=/tmp/infracost.json \
                                   --repo=$GITHUB_REPOSITORY \
                                   --github-token=${{github.token}} \
                                   --pull-request=${{github.event.pull_request.number}} \
                                   --behavior=update
c

crooked-daybreak-55253

01/05/2024, 6:39 PM
Hi Diego, can you share an example of the hcl and the change you’re making?
a

able-soccer-51632

01/05/2024, 9:31 PM
sure, i changed the
desired_count
to 10 instead 1
Copy code
inputs = {
  container = {
    image_uri               = var.registry_url
    name                    = "floorplan"
    port                    = 8080
    protocol                = "HTTP"
    cpu                     = 1024
    memory                  = 2048
    desired_count           = 1
    environment             = local.app_vars
c

crooked-daybreak-55253

01/05/2024, 9:50 PM
sorry I’m not super familiar with the ecs, do you have a more complete example with the resource blocks, etc?
a

able-soccer-51632

01/05/2024, 10:27 PM
no worries, if i change the CPU and Memory as well, like that:
Copy code
inputs = {
  container = {
    image_uri               = var.registry_url
    name                    = "floorplan"
    port                    = 8080
    protocol                = "HTTP"
    cpu                     = 4096
    memory                  = 16384
    desired_count           = 1
    environment             = local.app_vars
No changes in the cost estimation as well
when we changed the desired_count, We are increasing the number of Fargate containers, billing per container, so it should cost approximately 10x more in the first example.
c

crooked-daybreak-55253

01/05/2024, 10:37 PM
yeah I get that you’re changing the terragrunt module inputs, but without knowing more about the module it’s hard to figure out what’s going on. Maybe the best I can say is that I agree it’s weird that changing the desired count isn’t changing the cost. Do we give any cost for that service? Maybe we’re not detecting it as fargate for some reason.
a

able-soccer-51632

01/08/2024, 11:11 AM
Hi tim, sorry about the delay
i'm using a private module based on the Terraform ECS Service: https://registry.terraform.io/modules/terraform-aws-modules/ecs/aws/latest/submodules/service
I only make some changes (to guarantee the standard of services) such as region and network, apart from that....it is practically the same as the original module
c

crooked-daybreak-55253

01/08/2024, 12:44 PM
Hmm the docs to that module say “`desired_count`/`scale` is always ignored; the module is designed to utilize autoscaling by default (though it can be disabled)” so maybe that’s why the cost doesn’t change?
a

able-soccer-51632

01/08/2024, 1:01 PM
yes, however if this is changed from 1 to 10, in theory Fargate billing will increase in the same order. Since billing increases, I assume Infracost should detect this.
actually this is a question, I don't know if other people have had this problem before 😅
c

crooked-daybreak-55253

01/08/2024, 2:21 PM
Ok two questions: 1. If you just urn infracost breakdown from the cli do you get a non-zero estimate?
2. How are your task definitions created? Looking at the code, our estimate is based on the memory/cpu from the task definition. When I try estimating the module example from the registry, there are no task definitions so I get a zero estimate.
a

able-soccer-51632

01/08/2024, 3:04 PM
1. when i performed the command:
Copy code
infracost breakdown --path . --format json --out-file infracost-base.json
Changed the
desired_count
from 1 to 10 and run:
Copy code
infracost diff --path . --compare-to infracost-base.json
the result is always the same
about the TD: We have a memory and CPU capacity and we have an autoscaling that goes from 1 to 10. We have some limits configured, depending on the load, the ECS itself can increase to up to 10 containers. Each delete has a capacity that was defined in the parameters above.
Copy code
cpu                     = 1024
    memory                  = 2048
    desired_count           = 1
c

crooked-daybreak-55253

01/08/2024, 3:08 PM
I understand it’s the same, but is there an estimate at all? For example when i run
infracost breakdown --path .
against the example module I get:
Copy code
module.ecs_service.module.container_definition["fluent-bit"].aws_cloudwatch_log_group.this[0]                                                                
 ├─ Data ingested                                                                               Monthly cost depends on usage: $0.50 per GB                   
 ├─ Archival Storage                                                                            Monthly cost depends on usage: $0.03 per GB                   
 └─ Insights queries data scanned                                                               Monthly cost depends on usage: $0.005 per GB
Which means there was no estimate generated (because there was no task definition).
a

able-soccer-51632

01/08/2024, 5:37 PM
i can see some estimations like that:
Copy code
Name                                                                                                     Monthly Qty  Unit                  Monthly Cost 
                                                                                                                                                          
 aws_route53_record.lb_record                                                                                                                             
 ├─ Standard queries (first 1B)                                                                      Monthly cost depends on usage: $0.40 per 1M queries  
 ├─ Latency based routing queries (first 1B)                                                         Monthly cost depends on usage: $0.60 per 1M queries  
 └─ Geo DNS queries (first 1B)                                                                       Monthly cost depends on usage: $0.70 per 1M queries  
                                                                                                                                                          
 module.alb.aws_lb.this[0]                                                                                                                                
 ├─ Application load balancer                                                                                     730  hours                       $18.40 
 └─ Load balancer capacity units                                                                     Monthly cost depends on usage: $5.84 per LCU         
                                                                                                                                                          
 module.ecs_service.module.container_definition["admin-ui"].aws_cloudwatch_log_group.this[0]                                                              
 ├─ Data ingested                                                                                    Monthly cost depends on usage: $0.57 per GB          
 ├─ Archival Storage                                                                                 Monthly cost depends on usage: $0.03 per GB          
 └─ Insights queries data scanned                                                                    Monthly cost depends on usage: $0.0057 per GB
but the infracosts shows the same estimation value, regardless about the number of containers, the value is always the same.
c

crooked-daybreak-55253

01/09/2024, 4:43 PM
Yeah I guess it’s a little confusing, but there is no estimate for the ec2_service. The estimate is based on the aws_ec2_task_definition, so we must not be able to determine what that is for some reason. If we picked up the task definition the estimate would look like:
Copy code
module.ecs_service.aws_ecs_service.this[0]                                                                           
 ├─ Per GB per hour                                                       2  GB                                 $6.49 
 ├─ Per vCPU per hour                                                     1  CPU                               $29.55 
 └─ Inference accelerator (eia2.medium)                                 730  hours                             $87.60
a

able-soccer-51632

01/09/2024, 4:44 PM
Do you think I should run a terragrunt plan, export the result in JSON file, and then perform the infracost diff?
c

crooked-daybreak-55253

01/09/2024, 4:49 PM
I might try that locally first just to see if you get any estimate at all (since you’re not getting one with just the hcl). Other than that, it’s really hard to tell what’s going on without an example of how the task definitions are being passed to the module. If they’re generated dynamically or from a data block somehow, there may not be a way for us to provide an estimate.
a

able-soccer-51632

01/10/2024, 12:58 PM
Hi Tim, today I've tried to perform a
terragrunt run-all plan -out planfile
in the main branch (with 1 container) and run the same plan on my test branch (10 containers). No changes has been detected 😢
c

crooked-daybreak-55253

01/10/2024, 1:21 PM
Oh well it was worth a shot. Like I said the estimates are based off task definitions, not containers, but unfortunately I out of ideas without having a complete example to look at.
a

able-soccer-51632

01/10/2024, 1:33 PM
okay, i'll try to investigate deeply. Thanks for the help and for all informations provided 🙏
2 Views