Skip to content

Commit

Permalink
fix: Correctly lookup non us-east-1 prices for AWS DocumentDB (#2736)
Browse files Browse the repository at this point in the history
* test: add test cases for docdb is us-east-2

* fix: Correctly lookup non us-east-1 prices for AWS DocumentDB
  • Loading branch information
tim775 committed Nov 7, 2023
1 parent c75d771 commit 2eb9d68
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,41 @@
├─ I/O requests Monthly cost depends on usage: $0.20 per 1M requests
└─ CPU credits Monthly cost depends on usage: $0.09 per vCPU-hours

aws_docdb_cluster_instance.dbue2
├─ Database instance (on-demand, db.t3.medium) 730 hours $56.94
├─ Storage Monthly cost depends on usage: $0.10 per GB
├─ I/O requests Monthly cost depends on usage: $0.20 per 1M requests
└─ CPU credits Monthly cost depends on usage: $0.09 per vCPU-hours

aws_docdb_cluster_instance.large
├─ Database instance (on-demand, db.r5.4xlarge) 730 hours $1,617.68
├─ Storage 1,000 GB $100.00
└─ I/O requests 10 1M requests $2.00

aws_docdb_cluster_instance.largeue2
├─ Database instance (on-demand, db.r5.4xlarge) 730 hours $1,617.68
├─ Storage 1,000 GB $100.00
└─ I/O requests 10 1M requests $2.00

aws_docdb_cluster_instance.medium
├─ Database instance (on-demand, db.t3.medium) 730 hours $56.94
├─ Storage 1,000 GB $100.00
├─ I/O requests 10 1M requests $2.00
└─ CPU credits 10 vCPU-hours $0.90

OVERALL TOTAL $1,936.46
aws_docdb_cluster_instance.mediumue2
├─ Database instance (on-demand, db.t3.medium) 730 hours $56.94
├─ Storage 1,000 GB $100.00
├─ I/O requests 10 1M requests $2.00
└─ CPU credits 10 vCPU-hours $0.90

OVERALL TOTAL $3,872.92
──────────────────────────────────
3 cloud resources were detected:
3 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
6 cloud resources were detected:
6 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Project ┃ Monthly cost ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
┃ TestDocDBClusterInstanceGoldenFile ┃ $1,936
┃ TestDocDBClusterInstanceGoldenFile ┃ $3,873
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ provider "aws" {
secret_key = "mock_secret_key"
}

provider "aws" {
alias = "ue2"
region = "us-east-2"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
skip_region_validation = true
access_key = "mock_access_key"
secret_key = "mock_secret_key"
}


resource "aws_docdb_cluster_instance" "db" {
cluster_identifier = "fake123"
instance_class = "db.t3.medium"
Expand All @@ -22,3 +34,22 @@ resource "aws_docdb_cluster_instance" "large" {
cluster_identifier = "fake123"
instance_class = "db.r5.4xlarge"
}

resource "aws_docdb_cluster_instance" "dbue2" {
provider = aws.ue2
cluster_identifier = "fake123"
instance_class = "db.t3.medium"
}

resource "aws_docdb_cluster_instance" "mediumue2" {
provider = aws.ue2
cluster_identifier = "fake123"
instance_class = "db.t3.medium"
}

resource "aws_docdb_cluster_instance" "largeue2" {
provider = aws.ue2
cluster_identifier = "fake123"
instance_class = "db.r5.4xlarge"
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ resource_usage:

aws_docdb_cluster_instance.large:
data_storage_gb: 1000
monthly_io_requests: 10000000
monthly_io_requests: 10000000

aws_docdb_cluster_instance.mediumue2:
data_storage_gb: 1000
monthly_io_requests: 10000000
monthly_cpu_credit_hrs: 10

aws_docdb_cluster_instance.largeue2:
data_storage_gb: 1000
monthly_io_requests: 10000000
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@

Name Monthly Qty Unit Monthly Cost

aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot
└─ Backup storage Monthly cost depends on usage: $0.021 per GB

aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot_usage
└─ Backup storage 1,000 GB $21.00

OVERALL TOTAL $21.00
Name Monthly Qty Unit Monthly Cost

aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot
└─ Backup storage Monthly cost depends on usage: $0.021 per GB

aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot_ue2
└─ Backup storage Monthly cost depends on usage: $0.021 per GB

aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot_usage
└─ Backup storage 1,000 GB $21.00

aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot_usage_ue2
└─ Backup storage 1,000 GB $21.00

OVERALL TOTAL $42.00
──────────────────────────────────
2 cloud resources were detected:
2 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
4 cloud resources were detected:
4 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Project ┃ Monthly cost ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
┃ TestDocDBClusterSnapshotGoldenFile ┃ $21
┃ TestDocDBClusterSnapshotGoldenFile ┃ $42
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ provider "aws" {
secret_key = "mock_secret_key"
}

provider "aws" {
alias = "ue2"
region = "us-east-2"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
skip_region_validation = true
access_key = "mock_access_key"
secret_key = "mock_secret_key"
}

resource "aws_docdb_cluster_snapshot" "my_aws_docdb_cluster_snapshot" {
db_cluster_identifier = "fake"
db_cluster_snapshot_identifier = "resourcetestsnapshot1234"
Expand All @@ -17,3 +28,15 @@ resource "aws_docdb_cluster_snapshot" "my_aws_docdb_cluster_snapshot_usage" {
db_cluster_identifier = "fake"
db_cluster_snapshot_identifier = "resourcetestsnapshot1234"
}

resource "aws_docdb_cluster_snapshot" "my_aws_docdb_cluster_snapshot_ue2" {
provider = aws.ue2
db_cluster_identifier = "fake"
db_cluster_snapshot_identifier = "resourcetestsnapshot1234"
}

resource "aws_docdb_cluster_snapshot" "my_aws_docdb_cluster_snapshot_usage_ue2" {
provider = aws.ue2
db_cluster_identifier = "fake"
db_cluster_snapshot_identifier = "resourcetestsnapshot1234"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ version: 0.1
resource_usage:
aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot_usage:
backup_storage_gb: 1000

aws_docdb_cluster_snapshot.my_aws_docdb_cluster_snapshot_usage_ue2:
backup_storage_gb: 1000
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@

Name Monthly Qty Unit Monthly Cost

aws_docdb_cluster.my_docdb
└─ Backup storage Monthly cost depends on usage: $0.021 per GB

aws_docdb_cluster.my_docdb_usage
└─ Backup storage 10,000 GB $210.00

OVERALL TOTAL $210.00
Name Monthly Qty Unit Monthly Cost

aws_docdb_cluster.my_docdb
└─ Backup storage Monthly cost depends on usage: $0.021 per GB

aws_docdb_cluster.my_docdb_ue2
└─ Backup storage Monthly cost depends on usage: $0.021 per GB

aws_docdb_cluster.my_docdb_usage
└─ Backup storage 10,000 GB $210.00

aws_docdb_cluster.my_docdb_usage_ue2
└─ Backup storage 10,000 GB $210.00

OVERALL TOTAL $420.00
──────────────────────────────────
2 cloud resources were detected:
2 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
4 cloud resources were detected:
4 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Project ┃ Monthly cost ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
┃ TestNewDocDBClusterGoldenFile ┃ $210
┃ TestNewDocDBClusterGoldenFile ┃ $420
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ provider "aws" {
secret_key = "mock_secret_key"
}

provider "aws" {
alias = "ue2"
region = "us-east-2"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
skip_region_validation = true
access_key = "mock_access_key"
secret_key = "mock_secret_key"
}

resource "aws_docdb_cluster" "my_docdb" {
cluster_identifier = "my-docdb-cluster"
engine = "docdb"
Expand All @@ -27,3 +38,25 @@ resource "aws_docdb_cluster" "my_docdb_usage" {
preferred_backup_window = "07:00-09:00"
skip_final_snapshot = true
}

resource "aws_docdb_cluster" "my_docdb_ue2" {
provider = aws.ue2
cluster_identifier = "my-docdb-cluster"
engine = "docdb"
master_username = "foo"
master_password = "mustbeeightchars"
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
skip_final_snapshot = true
}

resource "aws_docdb_cluster" "my_docdb_usage_ue2" {
provider = aws.ue2
cluster_identifier = "my-docdb-cluster-usage"
engine = "docdb"
master_username = "foo"
master_password = "mustbeeightchars"
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
skip_final_snapshot = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ version: 0.1
resource_usage:
aws_docdb_cluster.my_docdb_usage:
backup_storage_gb: 10000

aws_docdb_cluster.my_docdb_usage_ue2:
backup_storage_gb: 10000
2 changes: 1 addition & 1 deletion internal/resources/aws/docdb_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *DocDBCluster) backupStorageCostComponent(backupStorage *decimal.Decimal
Service: strPtr("AmazonDocDB"),
ProductFamily: strPtr("Storage Snapshot"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", Value: strPtr("BackupUsage")},
{Key: "usagetype", ValueRegex: regexPtr("(^|-)BackupUsage$")},
},
},
}
Expand Down
8 changes: 5 additions & 3 deletions internal/resources/aws/docdb_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package aws

import (
"fmt"

"github.com/shopspring/decimal"

"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)

type DocDBClusterInstance struct {
Expand Down Expand Up @@ -72,7 +74,7 @@ func (r *DocDBClusterInstance) BuildResource() *schema.Resource {
Service: strPtr("AmazonDocDB"),
ProductFamily: strPtr("Database Storage"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", Value: strPtr("StorageUsage")},
{Key: "usagetype", ValueRegex: regexPtr("(^|-)StorageUsage$")},
},
},
PriceFilter: &schema.PriceFilter{
Expand All @@ -90,7 +92,7 @@ func (r *DocDBClusterInstance) BuildResource() *schema.Resource {
Service: strPtr("AmazonDocDB"),
ProductFamily: strPtr("System Operation"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", Value: strPtr("StorageIOUsage")},
{Key: "usagetype", ValueRegex: regexPtr("(^|-)StorageIOUsage$")},
},
},
},
Expand Down

0 comments on commit 2eb9d68

Please sign in to comment.