From 4686ecc1597f97a3d3b5668f1e80317194304d58 Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Tue, 7 May 2024 17:26:56 -0400 Subject: [PATCH 1/8] Add support for elasticsearch --- infracost-usage-example.yml | 6 + .../testdata/database_test/database_test.tf | 75 +++++++++++- .../database_test/database_test.usage.yml | 7 ++ internal/resources/ibm/database.go | 112 +++++++++++++++++- 4 files changed, 198 insertions(+), 2 deletions(-) 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. From 0947ced45863875cc1c3d61eb081d7b85a5581e9 Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Wed, 8 May 2024 02:02:50 -0400 Subject: [PATCH 2/8] Fix errors, separate usage variables --- infracost-usage-example.yml | 16 +- internal/providers/terraform/ibm/ibm.go | 1 + .../database_test/database_test.usage.yml | 20 +- internal/resources/ibm/database.go | 239 ++++++++++++------ 4 files changed, 180 insertions(+), 96 deletions(-) diff --git a/infracost-usage-example.yml b/infracost-usage-example.yml index 3d2cc587eae..0d63858cfcc 100644 --- a/infracost-usage-example.yml +++ b/infracost-usage-example.yml @@ -1357,13 +1357,13 @@ resource_usage: data_transfer_global: 2500 # Monthly global traffic through the gateway in GB ibm_database.postgres: - 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 + postgresql_database_ram_mb: 12288 # Allocated memory in MB per-member + postgresql_database_disk_mb: 131072 # Allocated disk in MB per-member + postgresql_database_core: 3 # Allocated dedicated CPU per-member + postgresql_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 + elasticsearch_database_ram_mb: 12288 # Allocated memory in MB per-member + elasticsearch_database_disk_mb: 131072 # Allocated disk in MB per-member + elasticsearch_database_core: 3 # Allocated dedicated CPU per-member + elasticsearch_database_members: 4 # Allocated number of members in the cluster diff --git a/internal/providers/terraform/ibm/ibm.go b/internal/providers/terraform/ibm/ibm.go index aabdb54355c..8aeb61c58ac 100644 --- a/internal/providers/terraform/ibm/ibm.go +++ b/internal/providers/terraform/ibm/ibm.go @@ -79,6 +79,7 @@ var globalCatalogServiceId = map[string]catalogMetadata{ "sysdig-secure": {"e831e900-82d6-11ec-95c5-c12c5a5d9687", []string{}, nil, "https://cloud.ibm.com/workload-protection/catalog/security-and-compliance-center-workload-protection"}, "logdna": {"e13e1860-959c-11e8-871e-ad157af61ad7", []string{}, nil, "https://cloud.ibm.com/catalog/services/logdna"}, "databases-for-postgresql": {"databases-for-postgresql", []string{}, nil, "https://cloud.ibm.com/databases/databases-for-postgresql/create"}, + "databases-for-elasticsearch": {"databases-for-elasticsearch", []string{}, nil, "https://cloud.ibm.com/databases/databases-for-elasticsearch/create"}, "secrets-manager": {"ebc0cdb0-af2a-11ea-98c7-29e5db822649", []string{}, nil, "https://cloud.ibm.com/catalog/services/secrets-manager"}, "appid": {"AdvancedMobileAccess-d6aece47-d840-45b0-8ab9-ad15354deeea", []string{}, nil, "https://cloud.ibm.com/catalog/services/appid"}, "appconnect": {"96a0ebf2-2a02-4e32-815f-7c09a1268c78", []string{}, nil, "https://www.ibm.com/products/app-connect/pricing"}, 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 240c6b9e21d..7a3e0d12739 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 @@ -1,16 +1,16 @@ version: 0.1 resource_usage: ibm_database.test_db1: - database_ram_mb: 12288 - database_disk_mb: 131072 - database_core: 3 + postgresql_database_ram_mb: 12288 + postgresql_database_disk_mb: 131072 + postgresql_database_core: 3 ibm_database.test_db2: - database_ram_mb: 15360 - database_members: 4 + postgresql_database_ram_mb: 15360 + postgresql_database_members: 4 ibm_database.test_es_enterprise_db1: - database_ram_mb: 12288 - database_disk_mb: 131072 - database_core: 3 + elasticsearch_database_ram_mb: 12288 + elasticsearch_database_disk_mb: 131072 + elasticsearch_database_core: 3 ibm_database.test_es_enterprise_db2: - database_ram_mb: 15360 - database_members: 4 \ No newline at end of file + elasticsearch_database_ram_mb: 15360 + elasticsearch_database_members: 4 \ No newline at end of file diff --git a/internal/resources/ibm/database.go b/internal/resources/ibm/database.go index 9e5f9f0d88f..c3cfe7c8b70 100644 --- a/internal/resources/ibm/database.go +++ b/internal/resources/ibm/database.go @@ -21,10 +21,15 @@ type Database struct { // Databases For PostgreSQL // Catalog Link: https://cloud.ibm.com/catalog/services/databases-for-postgresql // Pricing Link: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pricing - RAM *int64 `infracost_usage:"database_ram_mb"` - Disk *int64 `infracost_usage:"database_disk_mb"` - Core *int64 `infracost_usage:"database_core"` - Members *int64 `infracost_usage:"database_members"` + postgresql_RAM *int64 `infracost_usage:"postgresql_database_ram_mb"` + postgresql_Disk *int64 `infracost_usage:"postgresql_database_disk_mb"` + postgresql_Core *int64 `infracost_usage:"postgresql_database_core"` + postgresql_Members *int64 `infracost_usage:"postgresql_database_members"` + + elasticsearch_RAM *int64 `infracost_usage:"elasticsearch_database_ram_mb"` + elasticsearch_Disk *int64 `infracost_usage:"elasticsearch_database_disk_mb"` + elasticsearch_Core *int64 `infracost_usage:"elasticsearch_database_core"` + elasticsearch_Members *int64 `infracost_usage:"elasticsearch_database_members"` } type DatabaseCostComponentsFunc func(*Database) []*schema.CostComponent @@ -37,10 +42,14 @@ func (r *Database) PopulateUsage(u *schema.UsageData) { // DatabaseUsageSchema defines a list which represents the usage schema of Database. var DatabaseUsageSchema = []*schema.UsageItem{ - {Key: "database_ram_mb", DefaultValue: 0, ValueType: schema.Int64}, - {Key: "database_disk_mb", DefaultValue: 0, ValueType: schema.Int64}, - {Key: "database_core", DefaultValue: 0, ValueType: schema.Int64}, - {Key: "database_members", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "postgresql_database_ram_mb", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "postgresql_database_disk_mb", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "postgresql_database_core", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "postgresql_database_members", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "elasticsearch_database_ram_mb", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "elasticsearch_database_disk_mb", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "elasticsearch_database_core", DefaultValue: 0, ValueType: schema.Int64}, + {Key: "elasticsearch_database_members", DefaultValue: 0, ValueType: schema.Int64}, } var DatabaseCostMap map[string]DatabaseCostComponentsFunc = map[string]DatabaseCostComponentsFunc{ @@ -61,14 +70,14 @@ func ConvertMBtoGB(d decimal.Decimal) decimal.Decimal { func PostgresRAMCostComponent(r *Database) *schema.CostComponent { var R decimal.Decimal - if r.RAM != nil { - R = ConvertMBtoGB(decimal.NewFromInt(*r.RAM)) + if r.postgresql_RAM != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.postgresql_RAM)) } else { // set the default R = decimal.NewFromInt(1) } var m decimal.Decimal - if r.Members != nil { - m = decimal.NewFromInt(*r.Members) + if r.postgresql_Members != nil { + m = decimal.NewFromInt(*r.postgresql_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -95,14 +104,14 @@ func PostgresRAMCostComponent(r *Database) *schema.CostComponent { func PostgresDiskCostComponent(r *Database) *schema.CostComponent { var d decimal.Decimal - if r.Disk != nil { - d = ConvertMBtoGB(decimal.NewFromInt(*r.Disk)) + if r.postgresql_Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.postgresql_Disk)) } else { // set the default d = decimal.NewFromInt(5) } var m decimal.Decimal - if r.Members != nil { - m = decimal.NewFromInt(*r.Members) + if r.postgresql_Members != nil { + m = decimal.NewFromInt(*r.postgresql_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -129,14 +138,14 @@ func PostgresDiskCostComponent(r *Database) *schema.CostComponent { func PostgresCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.Core != nil { - c = decimal.NewFromInt(*r.Core) + if r.postgresql_Core != nil { + c = decimal.NewFromInt(*r.postgresql_Core) } else { // set the default c = decimal.NewFromInt(0) } var m decimal.Decimal - if r.Members != nil { - m = decimal.NewFromInt(*r.Members) + if r.postgresql_Members != nil { + m = decimal.NewFromInt(*r.postgresql_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -171,104 +180,178 @@ 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)) + if r.elasticsearch_RAM != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.elasticsearch_RAM)) } else { // set the default R = decimal.NewFromInt(1) } var m decimal.Decimal - if r.Members != nil { - m = decimal.NewFromInt(*r.Members) + if r.elasticsearch_Members != nil { + m = decimal.NewFromInt(*r.elasticsearch_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"), - }, + if r.Plan == "platinum" { + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_RAM"), + }, + } + return &costComponent + } else { + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_RAM"), + }, + } + return &costComponent } - return &costComponent } func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { var d decimal.Decimal - if r.Disk != nil { - d = ConvertMBtoGB(decimal.NewFromInt(*r.Disk)) + if r.elasticsearch_Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.elasticsearch_Disk)) } else { // set the default d = decimal.NewFromInt(5) } var m decimal.Decimal - if r.Members != nil { - m = decimal.NewFromInt(*r.Members) + if r.elasticsearch_Members != nil { + m = decimal.NewFromInt(*r.elasticsearch_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"), - }, + if r.Plan == "enterprise" { + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_DISK"), + }, + } + return &costComponent + } else { + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_DISK"), + }, + } + return &costComponent } - return &costComponent } func ElasticSearchCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.Core != nil { - c = decimal.NewFromInt(*r.Core) + if r.elasticsearch_Core != nil { + c = decimal.NewFromInt(*r.elasticsearch_Core) } else { // set the default c = decimal.NewFromInt(0) } var m decimal.Decimal - if r.Members != nil { - m = decimal.NewFromInt(*r.Members) + if r.elasticsearch_Members != nil { + m = decimal.NewFromInt(*r.elasticsearch_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"), - }, + if r.Plan == "enterprise" { + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("VIRTUAL_PROCESSOR_CORES"), + }, + } + return &costComponent + } else { + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("VIRTUAL_PROCESSOR_CORES"), + }, + } + return &costComponent } - return &costComponent } func GetElasticSearchCostComponents(r *Database) []*schema.CostComponent { From 53941a2f1b8ed2bfee9959181a5d9a583ef4e6fa Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Wed, 8 May 2024 02:25:25 -0400 Subject: [PATCH 3/8] update infracost usage example --- infracost-usage-example.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/infracost-usage-example.yml b/infracost-usage-example.yml index 0d63858cfcc..033e7fcd96e 100644 --- a/infracost-usage-example.yml +++ b/infracost-usage-example.yml @@ -89,10 +89,14 @@ resource_type_default_usage: data_transfer_global: 1000 data_transfer_local: 1000 ibm_database: - database_ram_mb: 12288 - database_disk_mb: 131072 - database_core: 3 - database_members: 4 + postgresql_database_ram_mb: 12288 + postgresql_database_disk_mb: 131072 + postgresql_database_core: 3 + postgresql_database_members: 4 + elasticsearch_database_ram_mb: 12288 + elasticsearch_database_disk_mb: 131072 + elasticsearch_database_core: 3 + elasticsearch_database_members: 4 resource_usage: # From d1d89b017530cabab77bec8b61fdf6c7da979f86 Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Wed, 8 May 2024 02:53:15 -0400 Subject: [PATCH 4/8] fix database core variable --- .../database_test/database_test.golden | 20 ++++++++++++++++--- internal/resources/ibm/database.go | 12 +++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/internal/providers/terraform/ibm/testdata/database_test/database_test.golden b/internal/providers/terraform/ibm/testdata/database_test/database_test.golden index 9586db00386..de6767ae62b 100644 --- a/internal/providers/terraform/ibm/testdata/database_test/database_test.golden +++ b/internal/providers/terraform/ibm/testdata/database_test/database_test.golden @@ -15,7 +15,21 @@ └─ Disk (first 1 GB-DISK) 1 GB-DISK $0.61 └─ Disk (over 0 GB-DISK) 1 GB-DISK $0.63 - OVERALL TOTAL $87.45 + ibm_database.test_es_enterprise_db1 + ├─ RAM (first 1 GB-RAM) 1 GB-RAM $15.70 + ├─ RAM (over 0 GB-RAM) 1 GB-RAM $16.17 + ├─ Disk (first 1 GB-DISK) 1 GB-DISK $0.61 + ├─ Disk (over 0 GB-DISK) 1 GB-DISK $0.63 + └─ Core (first 1 Virtual Processor Core) 1 Virtual Processor Core $31.40 + └─ Core (over 0 Virtual Processor Core) 1 Virtual Processor Core $32.34 + + ibm_database.test_es_enterprise_db2 + ├─ RAM (first 1 GB-RAM) 1 GB-RAM $15.70 + ├─ RAM (over 0 GB-RAM) 1 GB-RAM $16.17 + └─ Disk (first 1 GB-DISK) 1 GB-DISK $0.61 + └─ Disk (over 0 GB-DISK) 1 GB-DISK $0.63 + + OVERALL TOTAL $217.41 ────────────────────────────────── -2 cloud resources were detected: -∙ 2 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file \ No newline at end of file +4 cloud resources were detected: +∙ 4 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file \ No newline at end of file diff --git a/internal/resources/ibm/database.go b/internal/resources/ibm/database.go index c3cfe7c8b70..561eda30de8 100644 --- a/internal/resources/ibm/database.go +++ b/internal/resources/ibm/database.go @@ -23,12 +23,12 @@ type Database struct { // Pricing Link: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pricing postgresql_RAM *int64 `infracost_usage:"postgresql_database_ram_mb"` postgresql_Disk *int64 `infracost_usage:"postgresql_database_disk_mb"` - postgresql_Core *int64 `infracost_usage:"postgresql_database_core"` + Core_postgresql *int64 `infracost_usage:"postgresql_database_core"` postgresql_Members *int64 `infracost_usage:"postgresql_database_members"` elasticsearch_RAM *int64 `infracost_usage:"elasticsearch_database_ram_mb"` elasticsearch_Disk *int64 `infracost_usage:"elasticsearch_database_disk_mb"` - elasticsearch_Core *int64 `infracost_usage:"elasticsearch_database_core"` + Core_elasticsearch *int64 `infracost_usage:"elasticsearch_database_core"` elasticsearch_Members *int64 `infracost_usage:"elasticsearch_database_members"` } @@ -138,8 +138,8 @@ func PostgresDiskCostComponent(r *Database) *schema.CostComponent { func PostgresCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.postgresql_Core != nil { - c = decimal.NewFromInt(*r.postgresql_Core) + if r.Core_postgresql != nil { + c = decimal.NewFromInt(*r.Core_postgresql) } else { // set the default c = decimal.NewFromInt(0) } @@ -297,8 +297,8 @@ func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { func ElasticSearchCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.elasticsearch_Core != nil { - c = decimal.NewFromInt(*r.elasticsearch_Core) + if r.Core_elasticsearch != nil { + c = decimal.NewFromInt(*r.Core_elasticsearch) } else { // set the default c = decimal.NewFromInt(0) } From 3c4f946c49ce354f7695d9c88b9cbe859a887100 Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Wed, 8 May 2024 09:48:15 -0400 Subject: [PATCH 5/8] Update variable to begin with a capital --- internal/resources/ibm/database.go | 64 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/internal/resources/ibm/database.go b/internal/resources/ibm/database.go index 561eda30de8..c2c1b37833f 100644 --- a/internal/resources/ibm/database.go +++ b/internal/resources/ibm/database.go @@ -21,15 +21,15 @@ type Database struct { // Databases For PostgreSQL // Catalog Link: https://cloud.ibm.com/catalog/services/databases-for-postgresql // Pricing Link: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pricing - postgresql_RAM *int64 `infracost_usage:"postgresql_database_ram_mb"` - postgresql_Disk *int64 `infracost_usage:"postgresql_database_disk_mb"` - Core_postgresql *int64 `infracost_usage:"postgresql_database_core"` - postgresql_Members *int64 `infracost_usage:"postgresql_database_members"` + Postgresql_RAM *int64 `infracost_usage:"postgresql_database_ram_mb"` + Postgresql_Disk *int64 `infracost_usage:"postgresql_database_disk_mb"` + Postgresql_Core *int64 `infracost_usage:"postgresql_database_core"` + Postgresql_Members *int64 `infracost_usage:"postgresql_database_members"` - elasticsearch_RAM *int64 `infracost_usage:"elasticsearch_database_ram_mb"` - elasticsearch_Disk *int64 `infracost_usage:"elasticsearch_database_disk_mb"` - Core_elasticsearch *int64 `infracost_usage:"elasticsearch_database_core"` - elasticsearch_Members *int64 `infracost_usage:"elasticsearch_database_members"` + Elasticsearch_RAM *int64 `infracost_usage:"elasticsearch_database_ram_mb"` + Elasticsearch_Disk *int64 `infracost_usage:"elasticsearch_database_disk_mb"` + Elasticsearch_Core *int64 `infracost_usage:"elasticsearch_database_core"` + Elasticsearch_Members *int64 `infracost_usage:"elasticsearch_database_members"` } type DatabaseCostComponentsFunc func(*Database) []*schema.CostComponent @@ -70,14 +70,14 @@ func ConvertMBtoGB(d decimal.Decimal) decimal.Decimal { func PostgresRAMCostComponent(r *Database) *schema.CostComponent { var R decimal.Decimal - if r.postgresql_RAM != nil { - R = ConvertMBtoGB(decimal.NewFromInt(*r.postgresql_RAM)) + if r.Postgresql_RAM != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.Postgresql_RAM)) } else { // set the default R = decimal.NewFromInt(1) } var m decimal.Decimal - if r.postgresql_Members != nil { - m = decimal.NewFromInt(*r.postgresql_Members) + if r.Postgresql_Members != nil { + m = decimal.NewFromInt(*r.Postgresql_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -104,14 +104,14 @@ func PostgresRAMCostComponent(r *Database) *schema.CostComponent { func PostgresDiskCostComponent(r *Database) *schema.CostComponent { var d decimal.Decimal - if r.postgresql_Disk != nil { - d = ConvertMBtoGB(decimal.NewFromInt(*r.postgresql_Disk)) + if r.Postgresql_Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.Postgresql_Disk)) } else { // set the default d = decimal.NewFromInt(5) } var m decimal.Decimal - if r.postgresql_Members != nil { - m = decimal.NewFromInt(*r.postgresql_Members) + if r.Postgresql_Members != nil { + m = decimal.NewFromInt(*r.Postgresql_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -138,14 +138,14 @@ func PostgresDiskCostComponent(r *Database) *schema.CostComponent { func PostgresCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.Core_postgresql != nil { - c = decimal.NewFromInt(*r.Core_postgresql) + if r.Postgresql_Core != nil { + c = decimal.NewFromInt(*r.Postgresql_Core) } else { // set the default c = decimal.NewFromInt(0) } var m decimal.Decimal - if r.postgresql_Members != nil { - m = decimal.NewFromInt(*r.postgresql_Members) + if r.Postgresql_Members != nil { + m = decimal.NewFromInt(*r.Postgresql_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -180,14 +180,14 @@ func GetPostgresCostComponents(r *Database) []*schema.CostComponent { func ElasticSearchRAMCostComponent(r *Database) *schema.CostComponent { var R decimal.Decimal - if r.elasticsearch_RAM != nil { - R = ConvertMBtoGB(decimal.NewFromInt(*r.elasticsearch_RAM)) + if r.Elasticsearch_RAM != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.Elasticsearch_RAM)) } else { // set the default R = decimal.NewFromInt(1) } var m decimal.Decimal - if r.elasticsearch_Members != nil { - m = decimal.NewFromInt(*r.elasticsearch_Members) + if r.Elasticsearch_Members != nil { + m = decimal.NewFromInt(*r.Elasticsearch_Members) } else { // set the default m = decimal.NewFromInt(3) } @@ -239,14 +239,14 @@ func ElasticSearchRAMCostComponent(r *Database) *schema.CostComponent { func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { var d decimal.Decimal - if r.elasticsearch_Disk != nil { - d = ConvertMBtoGB(decimal.NewFromInt(*r.elasticsearch_Disk)) + if r.Elasticsearch_Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.Elasticsearch_Disk)) } else { // set the default d = decimal.NewFromInt(5) } var m decimal.Decimal - if r.elasticsearch_Members != nil { - m = decimal.NewFromInt(*r.elasticsearch_Members) + if r.Elasticsearch_Members != nil { + m = decimal.NewFromInt(*r.Elasticsearch_Members) } else { // set the default m = decimal.NewFromInt(3) } @@ -297,14 +297,14 @@ func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { func ElasticSearchCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.Core_elasticsearch != nil { - c = decimal.NewFromInt(*r.Core_elasticsearch) + if r.Elasticsearch_Core != nil { + c = decimal.NewFromInt(*r.Elasticsearch_Core) } else { // set the default c = decimal.NewFromInt(0) } var m decimal.Decimal - if r.elasticsearch_Members != nil { - m = decimal.NewFromInt(*r.elasticsearch_Members) + if r.Elasticsearch_Members != nil { + m = decimal.NewFromInt(*r.Elasticsearch_Members) } else { // set the default m = decimal.NewFromInt(3) } From e00ba78f5c596428a409090a5f8cae692891a32c Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Wed, 8 May 2024 10:01:31 -0400 Subject: [PATCH 6/8] Removed plan for ES and updated variable names to be consistent --- internal/resources/ibm/database.go | 237 +++++++++++------------------ 1 file changed, 86 insertions(+), 151 deletions(-) diff --git a/internal/resources/ibm/database.go b/internal/resources/ibm/database.go index c2c1b37833f..cb843ccda81 100644 --- a/internal/resources/ibm/database.go +++ b/internal/resources/ibm/database.go @@ -21,15 +21,18 @@ type Database struct { // Databases For PostgreSQL // Catalog Link: https://cloud.ibm.com/catalog/services/databases-for-postgresql // Pricing Link: https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-pricing - Postgresql_RAM *int64 `infracost_usage:"postgresql_database_ram_mb"` - Postgresql_Disk *int64 `infracost_usage:"postgresql_database_disk_mb"` - Postgresql_Core *int64 `infracost_usage:"postgresql_database_core"` - Postgresql_Members *int64 `infracost_usage:"postgresql_database_members"` + PostgreSQL_Ram *int64 `infracost_usage:"postgresql_database_ram_mb"` + PostgreSQL_Disk *int64 `infracost_usage:"postgresql_database_disk_mb"` + PostgreSQL_Core *int64 `infracost_usage:"postgresql_database_core"` + PostgreSQL_Members *int64 `infracost_usage:"postgresql_database_members"` - Elasticsearch_RAM *int64 `infracost_usage:"elasticsearch_database_ram_mb"` - Elasticsearch_Disk *int64 `infracost_usage:"elasticsearch_database_disk_mb"` - Elasticsearch_Core *int64 `infracost_usage:"elasticsearch_database_core"` - Elasticsearch_Members *int64 `infracost_usage:"elasticsearch_database_members"` + // Databases For ElasticSearch + // Catalog Link: https://cloud.ibm.com/catalog/services/databases-for-elasticsearch + // Pricing Link: https://cloud.ibm.com/docs/databases-for-elasticsearch?topic=databases-for-elasticsearch-pricing + ElasticSearch_Ram *int64 `infracost_usage:"elasticsearch_database_ram_mb"` + ElasticSearch_Disk *int64 `infracost_usage:"elasticsearch_database_disk_mb"` + ElasticSearch_Core *int64 `infracost_usage:"elasticsearch_database_core"` + ElasticSearch_Members *int64 `infracost_usage:"elasticsearch_database_members"` } type DatabaseCostComponentsFunc func(*Database) []*schema.CostComponent @@ -70,14 +73,14 @@ func ConvertMBtoGB(d decimal.Decimal) decimal.Decimal { func PostgresRAMCostComponent(r *Database) *schema.CostComponent { var R decimal.Decimal - if r.Postgresql_RAM != nil { - R = ConvertMBtoGB(decimal.NewFromInt(*r.Postgresql_RAM)) + if r.PostgreSQL_Ram != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.PostgreSQL_Ram)) } else { // set the default R = decimal.NewFromInt(1) } var m decimal.Decimal - if r.Postgresql_Members != nil { - m = decimal.NewFromInt(*r.Postgresql_Members) + if r.PostgreSQL_Members != nil { + m = decimal.NewFromInt(*r.PostgreSQL_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -104,14 +107,14 @@ func PostgresRAMCostComponent(r *Database) *schema.CostComponent { func PostgresDiskCostComponent(r *Database) *schema.CostComponent { var d decimal.Decimal - if r.Postgresql_Disk != nil { - d = ConvertMBtoGB(decimal.NewFromInt(*r.Postgresql_Disk)) + if r.PostgreSQL_Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.PostgreSQL_Disk)) } else { // set the default d = decimal.NewFromInt(5) } var m decimal.Decimal - if r.Postgresql_Members != nil { - m = decimal.NewFromInt(*r.Postgresql_Members) + if r.PostgreSQL_Members != nil { + m = decimal.NewFromInt(*r.PostgreSQL_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -138,14 +141,14 @@ func PostgresDiskCostComponent(r *Database) *schema.CostComponent { func PostgresCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.Postgresql_Core != nil { - c = decimal.NewFromInt(*r.Postgresql_Core) + if r.PostgreSQL_Core != nil { + c = decimal.NewFromInt(*r.PostgreSQL_Core) } else { // set the default c = decimal.NewFromInt(0) } var m decimal.Decimal - if r.Postgresql_Members != nil { - m = decimal.NewFromInt(*r.Postgresql_Members) + if r.PostgreSQL_Members != nil { + m = decimal.NewFromInt(*r.PostgreSQL_Members) } else { // set the default m = decimal.NewFromInt(2) } @@ -180,178 +183,110 @@ func GetPostgresCostComponents(r *Database) []*schema.CostComponent { func ElasticSearchRAMCostComponent(r *Database) *schema.CostComponent { var R decimal.Decimal - if r.Elasticsearch_RAM != nil { - R = ConvertMBtoGB(decimal.NewFromInt(*r.Elasticsearch_RAM)) + if r.ElasticSearch_Ram != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.ElasticSearch_Ram)) } else { // set the default R = decimal.NewFromInt(1) } var m decimal.Decimal - if r.Elasticsearch_Members != nil { - m = decimal.NewFromInt(*r.Elasticsearch_Members) + if r.ElasticSearch_Members != nil { + m = decimal.NewFromInt(*r.ElasticSearch_Members) } else { // set the default m = decimal.NewFromInt(3) } cost := R.Mul(m) - - if r.Plan == "platinum" { - 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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("GIGABYTE_MONTHS_RAM"), - }, - } - return &costComponent - } else { - 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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("GIGABYTE_MONTHS_RAM"), + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, }, - } - return &costComponent + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_RAM"), + }, } + return &costComponent } func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { var d decimal.Decimal - if r.Elasticsearch_Disk != nil { - d = ConvertMBtoGB(decimal.NewFromInt(*r.Elasticsearch_Disk)) + if r.ElasticSearch_Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.ElasticSearch_Disk)) } else { // set the default d = decimal.NewFromInt(5) } var m decimal.Decimal - if r.Elasticsearch_Members != nil { - m = decimal.NewFromInt(*r.Elasticsearch_Members) + if r.ElasticSearch_Members != nil { + m = decimal.NewFromInt(*r.ElasticSearch_Members) } else { // set the default m = decimal.NewFromInt(3) } cost := d.Mul(m) - if r.Plan == "enterprise" { - 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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("GIGABYTE_MONTHS_DISK"), - }, - } - return &costComponent - } else { - 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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("GIGABYTE_MONTHS_DISK"), + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, }, - } - return &costComponent + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_DISK"), + }, } + return &costComponent } func ElasticSearchCoreCostComponent(r *Database) *schema.CostComponent { var c decimal.Decimal - if r.Elasticsearch_Core != nil { - c = decimal.NewFromInt(*r.Elasticsearch_Core) + if r.ElasticSearch_Core != nil { + c = decimal.NewFromInt(*r.ElasticSearch_Core) } else { // set the default c = decimal.NewFromInt(0) } var m decimal.Decimal - if r.Elasticsearch_Members != nil { - m = decimal.NewFromInt(*r.Elasticsearch_Members) + if r.ElasticSearch_Members != nil { + m = decimal.NewFromInt(*r.ElasticSearch_Members) } else { // set the default m = decimal.NewFromInt(3) } cost := c.Mul(m) - - if r.Plan == "enterprise" { - 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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("VIRTUAL_PROCESSOR_CORES"), - }, - } - return &costComponent - } else { - 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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("VIRTUAL_PROCESSOR_CORES"), + 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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, }, - } - return &costComponent + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("VIRTUAL_PROCESSOR_CORES"), + }, } + return &costComponent } func GetElasticSearchCostComponents(r *Database) []*schema.CostComponent { From e187f1b3428c099ca17e205006f5385044f8ec53 Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Wed, 8 May 2024 10:04:45 -0400 Subject: [PATCH 7/8] Remove commented code --- .../testdata/database_test/database_test.tf | 37 ------------------- 1 file changed, 37 deletions(-) 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 4aeac1ee93e..2131bf8e0fc 100644 --- a/internal/providers/terraform/ibm/testdata/database_test/database_test.tf +++ b/internal/providers/terraform/ibm/testdata/database_test/database_test.tf @@ -94,40 +94,3 @@ resource "ibm_database" "test_es_enterprise_db2" { } } } - -# 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 From b0ad8e992e10bdf763c2bee9048d9748c2700b1e Mon Sep 17 00:00:00 2001 From: Eugene Koo Date: Tue, 4 Jun 2024 16:40:45 -0400 Subject: [PATCH 8/8] Refactor files, added test for platinum plan for elasticsearch --- .../database_test/database_test.golden | 11 +- .../testdata/database_test/database_test.tf | 37 ++++++ .../database_test/database_test.usage.yml | 7 + internal/resources/ibm/database.go | 116 ----------------- .../resources/ibm/database_elasticsearch.go | 122 ++++++++++++++++++ 5 files changed, 176 insertions(+), 117 deletions(-) create mode 100644 internal/resources/ibm/database_elasticsearch.go diff --git a/internal/providers/terraform/ibm/testdata/database_test/database_test.golden b/internal/providers/terraform/ibm/testdata/database_test/database_test.golden index de6767ae62b..1069e02cbe0 100644 --- a/internal/providers/terraform/ibm/testdata/database_test/database_test.golden +++ b/internal/providers/terraform/ibm/testdata/database_test/database_test.golden @@ -29,7 +29,16 @@ └─ Disk (first 1 GB-DISK) 1 GB-DISK $0.61 └─ Disk (over 0 GB-DISK) 1 GB-DISK $0.63 - OVERALL TOTAL $217.41 + ibm_database.test_es_platinum_db1 + ├─ RAM 36 GB-RAM $939.60 + ├─ Disk 384 GB-DISK $234.24 + └─ Core 9 Virtual Processor Core $282.60 + + ibm_database.test_es_platinum_db2 + ├─ RAM 4 GB-RAM $104.40 + └─ Disk 20 GB-DISK $12.20 + + OVERALL TOTAL $1,790.45 ────────────────────────────────── 4 cloud resources were detected: ∙ 4 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file \ No newline at end of file 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 2131bf8e0fc..d7b3cb1390d 100644 --- a/internal/providers/terraform/ibm/testdata/database_test/database_test.tf +++ b/internal/providers/terraform/ibm/testdata/database_test/database_test.tf @@ -94,3 +94,40 @@ resource "ibm_database" "test_es_enterprise_db2" { } } } + +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-platinum2" + service = "databases-for-elasticsearch" + plan = "platinum" + location = "eu-gb" + + group { + group_id = "member" + members { + allocation_count = 4 + } + 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 7a3e0d12739..0885884199b 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 @@ -13,4 +13,11 @@ resource_usage: elasticsearch_database_core: 3 ibm_database.test_es_enterprise_db2: elasticsearch_database_ram_mb: 15360 + elasticsearch_database_members: 4 + ibm_database.test_es_platinum_db1: + elasticsearch_database_ram_mb: 12288 + elasticsearch_database_disk_mb: 131072 + elasticsearch_database_core: 3 + ibm_database.test_es_platinum_db2: + elasticsearch_database_ram_mb: 1024 elasticsearch_database_members: 4 \ No newline at end of file diff --git a/internal/resources/ibm/database.go b/internal/resources/ibm/database.go index cb843ccda81..fce5b72aa9d 100644 --- a/internal/resources/ibm/database.go +++ b/internal/resources/ibm/database.go @@ -181,122 +181,6 @@ func GetPostgresCostComponents(r *Database) []*schema.CostComponent { } } -func ElasticSearchRAMCostComponent(r *Database) *schema.CostComponent { - var R decimal.Decimal - if r.ElasticSearch_Ram != nil { - R = ConvertMBtoGB(decimal.NewFromInt(*r.ElasticSearch_Ram)) - } else { // set the default - R = decimal.NewFromInt(1) - } - var m decimal.Decimal - if r.ElasticSearch_Members != nil { - m = decimal.NewFromInt(*r.ElasticSearch_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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("GIGABYTE_MONTHS_RAM"), - }, - } - return &costComponent -} - -func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { - var d decimal.Decimal - if r.ElasticSearch_Disk != nil { - d = ConvertMBtoGB(decimal.NewFromInt(*r.ElasticSearch_Disk)) - } else { // set the default - d = decimal.NewFromInt(5) - } - var m decimal.Decimal - if r.ElasticSearch_Members != nil { - m = decimal.NewFromInt(*r.ElasticSearch_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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - PriceFilter: &schema.PriceFilter{ - Unit: strPtr("GIGABYTE_MONTHS_DISK"), - }, - } - return &costComponent -} - -func ElasticSearchCoreCostComponent(r *Database) *schema.CostComponent { - var c decimal.Decimal - if r.ElasticSearch_Core != nil { - c = decimal.NewFromInt(*r.ElasticSearch_Core) - } else { // set the default - c = decimal.NewFromInt(0) - } - var m decimal.Decimal - if r.ElasticSearch_Members != nil { - m = decimal.NewFromInt(*r.ElasticSearch_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"), - AttributeFilters: []*schema.AttributeFilter{ - {Key: "planName", Value: &r.Plan}, - }, - }, - 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. diff --git a/internal/resources/ibm/database_elasticsearch.go b/internal/resources/ibm/database_elasticsearch.go new file mode 100644 index 00000000000..f725d5edfc2 --- /dev/null +++ b/internal/resources/ibm/database_elasticsearch.go @@ -0,0 +1,122 @@ +package ibm + +import ( + "github.com/infracost/infracost/internal/schema" + "github.com/shopspring/decimal" +) + +func ElasticSearchRAMCostComponent(r *Database) *schema.CostComponent { + var R decimal.Decimal + if r.ElasticSearch_Ram != nil { + R = ConvertMBtoGB(decimal.NewFromInt(*r.ElasticSearch_Ram)) + } else { // set the default + R = decimal.NewFromInt(1) + } + var m decimal.Decimal + if r.ElasticSearch_Members != nil { + m = decimal.NewFromInt(*r.ElasticSearch_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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_RAM"), + }, + } + return &costComponent +} + +func ElasticSearchDiskCostComponent(r *Database) *schema.CostComponent { + var d decimal.Decimal + if r.ElasticSearch_Disk != nil { + d = ConvertMBtoGB(decimal.NewFromInt(*r.ElasticSearch_Disk)) + } else { // set the default + d = decimal.NewFromInt(5) + } + var m decimal.Decimal + if r.ElasticSearch_Members != nil { + m = decimal.NewFromInt(*r.ElasticSearch_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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("GIGABYTE_MONTHS_DISK"), + }, + } + return &costComponent +} + +func ElasticSearchCoreCostComponent(r *Database) *schema.CostComponent { + var c decimal.Decimal + if r.ElasticSearch_Core != nil { + c = decimal.NewFromInt(*r.ElasticSearch_Core) + } else { // set the default + c = decimal.NewFromInt(0) + } + var m decimal.Decimal + if r.ElasticSearch_Members != nil { + m = decimal.NewFromInt(*r.ElasticSearch_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"), + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + 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), + } +} \ No newline at end of file