Skip to content

Commit

Permalink
add watson studio (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltol authored Apr 24, 2024
1 parent 2e9507b commit 6e76c49
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 18 deletions.
4 changes: 4 additions & 0 deletions infracost-usage-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
29 cloud resources were detected:
29 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
30 changes: 17 additions & 13 deletions internal/resources/ibm/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
64 changes: 64 additions & 0 deletions internal/resources/ibm/resource_instance_studio.go
Original file line number Diff line number Diff line change
@@ -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"),
},
}
}

0 comments on commit 6e76c49

Please sign in to comment.