diff --git a/infracost-usage-example.yml b/infracost-usage-example.yml index 059ce6b95ce..3d2cc587eae 100644 --- a/infracost-usage-example.yml +++ b/infracost-usage-example.yml @@ -1361,3 +1361,9 @@ resource_usage: database_disk_mb: 131072 # Allocated disk in MB per-member database_core: 3 # Allocated dedicated CPU per-member database_members: 4 # Allocated number of members in the cluster + + ibm_database.elasticsearch: + database_ram_mb: 12288 # Allocated memory in MB per-member + database_disk_mb: 131072 # Allocated disk in MB per-member + database_core: 3 # Allocated dedicated CPU per-member + database_members: 4 # Allocated number of members in the cluster diff --git a/internal/providers/terraform/ibm/testdata/database_test/database_test.tf b/internal/providers/terraform/ibm/testdata/database_test/database_test.tf index 79c8430a45d..4aeac1ee93e 100644 --- a/internal/providers/terraform/ibm/testdata/database_test/database_test.tf +++ b/internal/providers/terraform/ibm/testdata/database_test/database_test.tf @@ -1,4 +1,3 @@ - terraform { required_providers { ibm = { @@ -58,3 +57,77 @@ resource "ibm_database" "test_db2" { } CONFIGURATION } + +resource "ibm_database" "test_es_enterprise_db1" { + name = "demo-es-enterprise" + service = "databases-for-elasticsearch" + plan = "enterprise" + location = "eu-gb" + + group { + group_id = "member" + memory { + allocation_mb = 12288 + } + disk { + allocation_mb = 131072 + } + cpu { + allocation_count = 3 + } + } +} + +resource "ibm_database" "test_es_enterprise_db2" { + name = "demo-es-enterprise2" + service = "databases-for-elasticsearch" + plan = "enterprise" + location = "eu-gb" + + group { + group_id = "member" + members { + allocation_count = 4 + } + memory { + allocation_mb = 15360 + } + } +} + +# resource "ibm_database" "test_es_platinum_db1" { +# name = "demo-es-platinum" +# service = "databases-for-elasticsearch" +# plan = "platinum" +# location = "eu-gb" + +# group { +# group_id = "member" +# memory { +# allocation_mb = 12288 +# } +# disk { +# allocation_mb = 131072 +# } +# cpu { +# allocation_count = 3 +# } +# } +# } + +# resource "ibm_database" "test_es_platinum_db2" { +# name = "demo-es-platinum" +# service = "databases-for-elasticsearch" +# plan = "platinum" +# location = "eu-gb" + +# group { +# group_id = "member" +# members { +# allocation_count = 3 +# } +# memory { +# allocation_mb = 1024 +# } +# } +# } \ No newline at end of file diff --git a/internal/providers/terraform/ibm/testdata/database_test/database_test.usage.yml b/internal/providers/terraform/ibm/testdata/database_test/database_test.usage.yml index 005e4927a0b..240c6b9e21d 100644 --- a/internal/providers/terraform/ibm/testdata/database_test/database_test.usage.yml +++ b/internal/providers/terraform/ibm/testdata/database_test/database_test.usage.yml @@ -5,5 +5,12 @@ resource_usage: database_disk_mb: 131072 database_core: 3 ibm_database.test_db2: + database_ram_mb: 15360 + database_members: 4 + ibm_database.test_es_enterprise_db1: + database_ram_mb: 12288 + database_disk_mb: 131072 + database_core: 3 + ibm_database.test_es_enterprise_db2: database_ram_mb: 15360 database_members: 4 \ No newline at end of file diff --git a/internal/resources/ibm/database.go b/internal/resources/ibm/database.go index 552f13ec092..9e5f9f0d88f 100644 --- a/internal/resources/ibm/database.go +++ b/internal/resources/ibm/database.go @@ -47,7 +47,7 @@ var DatabaseCostMap map[string]DatabaseCostComponentsFunc = map[string]DatabaseC "databases-for-postgresql": GetPostgresCostComponents, // "databases-for-etcd": // "databases-for-redis": - // "databases-for-elasticsearch": + "databases-for-elasticsearch": GetElasticSearchCostComponents, // "messages-for-rabbitmq": // "databases-for-mongodb": // "databases-for-mysql": @@ -169,6 +169,116 @@ func GetPostgresCostComponents(r *Database) []*schema.CostComponent { } } +func ElasticSearchRAMCostComponent(r *Database) *schema.CostComponent { + var R decimal.Decimal + if r.RAM != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.RAM)) + } else { // set the default + R = decimal.NewFromInt(1) + } + var m decimal.Decimal + if r.Members != nil { + m = decimal.NewFromInt(*r.Members) + } else { // set the default + m = decimal.NewFromInt(3) + } + + cost := R.Mul(m) + + costComponent := schema.CostComponent{ + Name: "RAM", + Unit: "GB-RAM", + MonthlyQuantity: &cost, + UnitMultiplier: decimal.NewFromInt(1), + ProductFilter: &schema.ProductFilter{ + VendorName: strPtr("ibm"), + Region: strPtr(r.Location), + Service: strPtr("databases-for-elasticsearch"), + ProductFamily: strPtr("service"), + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_RAM"), + }, + } + return &costComponent +} + +func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { + var d decimal.Decimal + if r.Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.Disk)) + } else { // set the default + d = decimal.NewFromInt(5) + } + var m decimal.Decimal + if r.Members != nil { + m = decimal.NewFromInt(*r.Members) + } else { // set the default + m = decimal.NewFromInt(3) + } + + cost := d.Mul(m) + + costComponent := schema.CostComponent{ + Name: "Disk", + Unit: "GB-DISK", + MonthlyQuantity: &cost, + UnitMultiplier: decimal.NewFromInt(1), + ProductFilter: &schema.ProductFilter{ + VendorName: strPtr("ibm"), + Region: strPtr(r.Location), + Service: strPtr("databases-for-elasticsearch"), + ProductFamily: strPtr("service"), + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_DISK"), + }, + } + return &costComponent +} + +func ElasticSearchCoreCostComponent(r *Database) *schema.CostComponent { + var c decimal.Decimal + if r.Core != nil { + c = decimal.NewFromInt(*r.Core) + } else { // set the default + c = decimal.NewFromInt(0) + } + var m decimal.Decimal + if r.Members != nil { + m = decimal.NewFromInt(*r.Members) + } else { // set the default + m = decimal.NewFromInt(3) + } + + cost := c.Mul(m) + + costComponent := schema.CostComponent{ + Name: "Core", + Unit: "Virtual Processor Core", + MonthlyQuantity: &cost, + UnitMultiplier: decimal.NewFromInt(1), + ProductFilter: &schema.ProductFilter{ + VendorName: strPtr("ibm"), + Region: strPtr(r.Location), + Service: strPtr("databases-for-elasticsearch"), + ProductFamily: strPtr("service"), + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("VIRTUAL_PROCESSOR_CORES"), + }, + } + return &costComponent +} + +func GetElasticSearchCostComponents(r *Database) []*schema.CostComponent { + return []*schema.CostComponent{ + ElasticSearchRAMCostComponent(r), + ElasticSearchDiskCostComponent(r), + ElasticSearchCoreCostComponent(r), + } +} + // BuildResource builds a schema.Resource from a valid Database struct. // This method is called after the resource is initialised by an IaC provider. // See providers folder for more information.