infracost / infracost

Cloud cost estimates for Terraform in pull requests💰📉 Shift FinOps Left!
https://infracost.io
Apache License 2.0
11.07k stars 562 forks source link

`rds_cluster_instance` does not support `db.serverless` instance class #2344

Closed ckdake closed 5 months ago

ckdake commented 1 year ago

We use AWS RDS Serverless V2, and I'm expecting to see usage data when running infracost --sync-usage-file. Instead, I'm seeing this in the info output from infracost: No products found for module.database.aws_rds_cluster_instance.rds_cluster_instance Database instance (on-demand, db.serverless), using 0.00

The relevant terraform bits:

resource "aws_rds_cluster" "rds_cluster" {
  cluster_identifier = "production"
  engine             = "aurora-postgresql"
  engine_mode        = "provisioned"
  engine_version     = "14.6"
  database_name      = "production"

  serverlessv2_scaling_configuration {
    max_capacity = 8
    min_capacity = 2
  }

  enabled_cloudwatch_logs_exports = ["postgresql"]

  # [...]
}

resource "aws_rds_cluster_instance" "rds_cluster_instance" {
  identifier         = "primary"
  promotion_tier     = 0
  cluster_identifier = aws_rds_cluster.rds_cluster.id
  instance_class     = "db.serverless"
  engine             = aws_rds_cluster.rds_cluster.engine
  engine_version     = aws_rds_cluster.rds_cluster.engine_version

  performance_insights_enabled          = true
  performance_insights_retention_period = 7
  performance_insights_kms_key_id       = aws_kms_key.performance_insights_key.arn

  monitoring_interval = 60
  monitoring_role_arn = aws_iam_role.rds_enhanced_monitoring.arn

  # [...]
}

I'm running infracost with an AWS_PROFILE that has full administrative read access, and it's able to correctly pull usage data for all of the other resources we use.

Should infracost be able to find the product for this resource? Should I do something differently? Thanks!

hugorut commented 1 year ago

Hi @ckdake,

Thanks for raising this issue, and many thanks for including the Terraform snippet. I've tested this out on my machine and have replicated the issue. This seems to be because we don't support db.serverless instance_class for rds_cluster_instance. Right now it seems like we're not fetching the correct pricing entries from our cloud pricing API when the serverless option is used. Having a quick poke around the cloud pricing schema, it's not entirely obvious where these are hiding, as they don't seem to be displayed under the AmazonRDS service as would be expected. So it might be something going on with our scrapers. I'm going to rename the title of your issue to reflect adding support for the db serverless option.

On a further point, it seems we've confused you a little with the --sync-usage-file flag. This is experimental and only works for a set subset of resources: https://www.infracost.io/docs/features/usage_based_resources/#fetch-from-cloud-apis . We have a more robust solution called Actual Costs https://www.infracost.io/docs/infracost_cloud/actual_costs/ as part of our cloud product. You can also just specify the usage manually using the usage file: https://www.infracost.io/docs/features/usage_based_resources/#specify-usage-manually I hope this helps.

ckdake commented 1 year ago

Thanks! That all makes sense. This is my first run looking at usage-based resources. The nature of our setup makes manually getting things right a little more time consuming than is probably worth it (Too Many Things with vastly differing costs), and we're not quite ready for Infracost Cloud yet.

aliscott commented 5 months ago

We've added support for db.serverless v0.10.37