From 6e76c498ecde27049b90300fb8d18e2dc7b30664 Mon Sep 17 00:00:00 2001 From: Hilton Lem <101275725+hiltol@users.noreply.github.com> Date: Wed, 24 Apr 2024 14:24:44 -0400 Subject: [PATCH] add watson studio (#167) --- infracost-usage-example.yml | 4 ++ .../resource_instance_test.golden | 12 +++- .../resource_instance_test.tf | 17 ++++- .../resource_instance_test.usage.yml | 8 ++- internal/resources/ibm/resource_instance.go | 30 +++++---- .../resources/ibm/resource_instance_studio.go | 64 +++++++++++++++++++ 6 files changed, 117 insertions(+), 18 deletions(-) create mode 100644 internal/resources/ibm/resource_instance_studio.go diff --git a/infracost-usage-example.yml b/infracost-usage-example.yml index f9436591ab5..c1cac82930f 100644 --- a/infracost-usage-example.yml +++ b/infracost-usage-example.yml @@ -78,6 +78,7 @@ resource_type_default_usage: wd_custom_models: 4 wd_collections: 301 scc_evaluations: 1 + data-science-experience_CAPACITY_UNIT_HOURS: 1 ibm_tg_gateway: connection: 3 data_transfer_global: 1000 @@ -1331,6 +1332,9 @@ resource_usage: ibm_resource_instance.scc_trial: scc_evaluations: 1 + ibm_resource_instance.watson_studio_professional: + data-science-experience_CAPACITY_UNIT_HOURS: 1 # Amount of Capacity Unit-Hours used in a month + ibm_tg_gateway.tg_gateway: connection: 25 # Monthly number of connections to the gateway data_transfer_local: 2500 # Monthly local traffic through the gateway in GB diff --git a/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.golden b/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.golden index e65d663e8bd..7580e1c19e7 100644 --- a/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.golden +++ b/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.golden @@ -108,6 +108,12 @@ ├─ Additional Monthly Documents 1,000 Documents $50.00 └─ Additional Monthly Queries 1,000 Queries $20.00 + ibm_resource_instance.watson_studio_lite + └─ Lite plan 1 $0.00 + + ibm_resource_instance.watson_studio_professional + └─ Capacity Unit-Hours 1 CUH $1.02 + ibm_resource_instance.wml_instance_essentials ├─ Capacity Unit-Hours 20 CUH $10.40 ├─ Class 1 Resource Units 50 RU $0.03 @@ -124,7 +130,7 @@ ├─ Class 2 Resource Units 50 RU $0.09 └─ Class 3 Resource Units 50 RU $0.25 - OVERALL TOTAL $15,473.53 + OVERALL TOTAL $15,474.55 ────────────────────────────────── -27 cloud resources were detected: -∙ 27 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file \ No newline at end of file +29 cloud resources were detected: +∙ 29 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/resource_instance_test/resource_instance_test.tf b/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.tf index 0e9c64ca8cc..b4c2e557fe7 100644 --- a/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.tf +++ b/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.tf @@ -203,7 +203,6 @@ resource "ibm_resource_instance" "watson_discovery_enterprise" { } # Security and Compliance Center (SCC) - resource "ibm_resource_instance" "scc_standard" { name = "scc_standard" service = "compliance" @@ -219,3 +218,19 @@ resource "ibm_resource_instance" "scc_trial" { location = "us-south" resource_group_id = "default" } + +resource "ibm_resource_instance" "watson_studio_professional" { + name = "ws_professional" + service = "data-science-experience" + plan = "professional-v1" + location = "us-south" + resource_group_id = "default" +} + +resource "ibm_resource_instance" "watson_studio_lite" { + name = "ws_lie" + service = "data-science-experience" + plan = "free-v1" + location = "us-south" + resource_group_id = "default" +} diff --git a/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.usage.yml b/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.usage.yml index 7f39aca2a16..334c9fa7edb 100644 --- a/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.usage.yml +++ b/internal/providers/terraform/ibm/testdata/resource_instance_test/resource_instance_test.usage.yml @@ -73,4 +73,10 @@ resource_usage: scc_evaluations: 1000 # Large enough to make sure all decimals are correct ibm_resource_instance.scc_trial: - scc_evaluations: 1000 # Large enough to make sure any potential cost will be picked up by the test \ No newline at end of file + scc_evaluations: 1000 # Large enough to make sure any potential cost will be picked up by the test + + ibm_resource_instance.watson_studio_professional: + data-science-experience_CAPACITY_UNIT_HOURS: 1 + + ibm_resource_instance.watson_studio_lite: + data-science-experience_CAPACITY_UNIT_HOURS: 10 diff --git a/internal/resources/ibm/resource_instance.go b/internal/resources/ibm/resource_instance.go index ebd20aca34f..a38ad1c3146 100644 --- a/internal/resources/ibm/resource_instance.go +++ b/internal/resources/ibm/resource_instance.go @@ -76,6 +76,8 @@ type ResourceInstance struct { WD_Collections *float64 `infracost_usage:"wd_collections"` // Security and Compliance Center (SCC) SCC_Evaluations *float64 `infracost_usage:"scc_evaluations"` + // Watson Studio + WS_CUH *float64 `infracost_usage:"data-science-experience_CAPACITY_UNIT_HOURS"` } type ResourceCostComponentsFunc func(*ResourceInstance) []*schema.CostComponent @@ -119,22 +121,24 @@ var ResourceInstanceUsageSchema = []*schema.UsageItem{ {Key: "wd_custom_models", DefaultValue: 0, ValueType: schema.Float64}, {Key: "wd_collections", DefaultValue: 0, ValueType: schema.Float64}, {Key: "scc_evaluations", DefaultValue: 0, ValueType: schema.Float64}, + {Key: "data-science-experience_CAPACITY_UNIT_HOURS", DefaultValue: 1, ValueType: schema.Float64}, } var ResourceInstanceCostMap map[string]ResourceCostComponentsFunc = map[string]ResourceCostComponentsFunc{ - "kms": GetKMSCostComponents, - "secrets-manager": GetSecretsManagerCostComponents, - "appid": GetAppIDCostComponents, - "appconnect": GetAppConnectCostComponents, - "power-iaas": GetPowerCostComponents, - "logdna": GetLogDNACostComponents, - "logdnaat": GetActivityTrackerCostComponents, - "sysdig-monitor": GetSysdigCostComponenets, - "continuous-delivery": GetContinuousDeliveryCostComponenets, - "pm-20": GetWMLCostComponents, - "conversation": GetWACostComponents, - "discovery": GetWDCostComponents, - "compliance": GetSCCCostComponents, + "kms": GetKMSCostComponents, + "secrets-manager": GetSecretsManagerCostComponents, + "appid": GetAppIDCostComponents, + "appconnect": GetAppConnectCostComponents, + "power-iaas": GetPowerCostComponents, + "logdna": GetLogDNACostComponents, + "logdnaat": GetActivityTrackerCostComponents, + "sysdig-monitor": GetSysdigCostComponenets, + "continuous-delivery": GetContinuousDeliveryCostComponenets, + "pm-20": GetWMLCostComponents, + "conversation": GetWACostComponents, + "discovery": GetWDCostComponents, + "compliance": GetSCCCostComponents, + "data-science-experience": GetWSCostComponents, } func KMSKeyVersionsFreeCostComponent(r *ResourceInstance) *schema.CostComponent { diff --git a/internal/resources/ibm/resource_instance_studio.go b/internal/resources/ibm/resource_instance_studio.go new file mode 100644 index 00000000000..2f07fb2c301 --- /dev/null +++ b/internal/resources/ibm/resource_instance_studio.go @@ -0,0 +1,64 @@ +package ibm + +import ( + "fmt" + + "github.com/infracost/infracost/internal/schema" + "github.com/shopspring/decimal" +) + +/* + * professional-v1 = "Professional" pricing plan + * free-v1 = "Lite" free plan + */ +func GetWSCostComponents(r *ResourceInstance) []*schema.CostComponent { + if r.Plan == "professional-v1" { + return []*schema.CostComponent{ + WSCapacityUnitHoursCostComponent(r), + } + } else if r.Plan == "free-v1" { + costComponent := schema.CostComponent{ + Name: "Lite plan", + UnitMultiplier: decimal.NewFromInt(1), + MonthlyQuantity: decimalPtr(decimal.NewFromInt(1)), + } + costComponent.SetCustomPrice(decimalPtr(decimal.NewFromInt(0))) + return []*schema.CostComponent{ + &costComponent, + } + } else { + costComponent := schema.CostComponent{ + Name: fmt.Sprintf("Plan %s with customized pricing", r.Plan), + UnitMultiplier: decimal.NewFromInt(1), + MonthlyQuantity: decimalPtr(decimal.NewFromInt(1)), + } + costComponent.SetCustomPrice(decimalPtr(decimal.NewFromInt(0))) + return []*schema.CostComponent{ + &costComponent, + } + } +} + +func WSCapacityUnitHoursCostComponent(r *ResourceInstance) *schema.CostComponent { + var q *decimal.Decimal + if r.WS_CUH != nil { + q = decimalPtr(decimal.NewFromFloat(*r.WS_CUH)) + } + return &schema.CostComponent{ + Name: "Capacity Unit-Hours", + Unit: "CUH", + UnitMultiplier: decimal.NewFromInt(1), + MonthlyQuantity: q, + ProductFilter: &schema.ProductFilter{ + VendorName: strPtr("ibm"), + Region: strPtr(r.Location), + Service: &r.Service, + AttributeFilters: []*schema.AttributeFilter{ + {Key: "planName", Value: &r.Plan}, + }, + }, + PriceFilter: &schema.PriceFilter{ + Unit: strPtr("CAPACITY_UNIT_HOURS"), + }, + } +}