From 42ad340167883b5261a339f571379b0bef4257cd Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Wed, 24 Apr 2024 14:12:55 -0400 Subject: [PATCH 1/8] Create inital WP file & parent cost component --- .../ibm/resource_instance_sysdig-secure.go | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 internal/resources/ibm/resource_instance_sysdig-secure.go diff --git a/internal/resources/ibm/resource_instance_sysdig-secure.go b/internal/resources/ibm/resource_instance_sysdig-secure.go new file mode 100644 index 00000000000..f61e74a3a13 --- /dev/null +++ b/internal/resources/ibm/resource_instance_sysdig-secure.go @@ -0,0 +1,26 @@ +package ibm + +var TRIAL_PLAN_PROGRAMMATIC_NAME string = "free-trial" +var GRADUATED_PLAN_PROGRAMMATIC_NAME string = "graduated-tier" + +func GetSysdigSecureCostComponents(r *ResourceInstance []*schema.CostComponent) { + if r.Plan == TRIAL_PLAN_PROGRAMMATIC_NAME { + return []*schema.CostComponent{ + // TODO + } + } else if r.Plan == GRADUATED_PLAN_PROGRAMMATIC_NAME { + return []*schema.CostComponent{ + // TODO + } + } else { + costComponent := schema.CostComponent{ + Name: fmt.Sprintf("Plan %s with customized pricing", r.Plan), + UnitMultiplier: decimal.NewFromInt(1), // Final quantity for this cost component will be divided by this amount + MonthlyQuantity: decimalPtr(decimal.NewFromInt(1)), + } + costComponent.SetCustomPrice(decimalPtr(decimal.NewFromInt(0))) + return []*schema.CostComponent{ + &costComponent, + } + } +} \ No newline at end of file From 801a0b85b80f3c5a1f20b468a722648b1282beb2 Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Thu, 25 Apr 2024 14:27:53 -0400 Subject: [PATCH 2/8] Fix function definition syntax --- internal/resources/ibm/resource_instance_sysdig-secure.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/resources/ibm/resource_instance_sysdig-secure.go b/internal/resources/ibm/resource_instance_sysdig-secure.go index f61e74a3a13..12b6c7970c4 100644 --- a/internal/resources/ibm/resource_instance_sysdig-secure.go +++ b/internal/resources/ibm/resource_instance_sysdig-secure.go @@ -3,7 +3,7 @@ package ibm var TRIAL_PLAN_PROGRAMMATIC_NAME string = "free-trial" var GRADUATED_PLAN_PROGRAMMATIC_NAME string = "graduated-tier" -func GetSysdigSecureCostComponents(r *ResourceInstance []*schema.CostComponent) { +func GetSysdigSecureCostComponents(r *ResourceInstance) []*schema.CostComponent { if r.Plan == TRIAL_PLAN_PROGRAMMATIC_NAME { return []*schema.CostComponent{ // TODO @@ -23,4 +23,6 @@ func GetSysdigSecureCostComponents(r *ResourceInstance []*schema.CostComponent) &costComponent, } } -} \ No newline at end of file +} + +func SysdigSecure \ No newline at end of file From cda2e77114bd4fc0914cf20a35b463a853e1dca7 Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Thu, 25 Apr 2024 16:57:35 -0400 Subject: [PATCH 3/8] Change global var names to avoid clashing --- internal/resources/ibm/resource_instance_scc.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/resources/ibm/resource_instance_scc.go b/internal/resources/ibm/resource_instance_scc.go index 34aa2e1c9c5..6497b197f11 100644 --- a/internal/resources/ibm/resource_instance_scc.go +++ b/internal/resources/ibm/resource_instance_scc.go @@ -7,15 +7,15 @@ import ( "github.com/shopspring/decimal" ) -const STANDARD_PLAN_PROGRAMMATIC_NAME string = "security-compliance-center-standard-plan" -const TRIAL_PLAN_PROGRAMMATIC_NAME string = "security-compliance-center-trial-plan" +const SCC_STANDARD_PLAN_PROGRAMMATIC_NAME string = "security-compliance-center-standard-plan" +const SCC_TRIAL_PLAN_PROGRAMMATIC_NAME string = "security-compliance-center-trial-plan" func GetSCCCostComponents(r *ResourceInstance) []*schema.CostComponent { - if r.Plan == STANDARD_PLAN_PROGRAMMATIC_NAME { + if r.Plan == SCC_STANDARD_PLAN_PROGRAMMATIC_NAME { return []*schema.CostComponent{ SCCMonthlyEvaluationsCostComponent(r), } - } else if r.Plan == TRIAL_PLAN_PROGRAMMATIC_NAME { + } else if r.Plan == SCC_TRIAL_PLAN_PROGRAMMATIC_NAME { costComponent := schema.CostComponent{ Name: "Trial", UnitMultiplier: decimal.NewFromInt(1), From 746cf07b1620117488beb78ea337b10d313fd5b4 Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Thu, 25 Apr 2024 16:57:56 -0400 Subject: [PATCH 4/8] Add cost components for SSC WP --- .../ibm/resource_instance_sysdig-secure.go | 119 ++++++++++++++++-- 1 file changed, 111 insertions(+), 8 deletions(-) diff --git a/internal/resources/ibm/resource_instance_sysdig-secure.go b/internal/resources/ibm/resource_instance_sysdig-secure.go index 12b6c7970c4..9dfed84a7c3 100644 --- a/internal/resources/ibm/resource_instance_sysdig-secure.go +++ b/internal/resources/ibm/resource_instance_sysdig-secure.go @@ -1,16 +1,31 @@ package ibm -var TRIAL_PLAN_PROGRAMMATIC_NAME string = "free-trial" -var GRADUATED_PLAN_PROGRAMMATIC_NAME string = "graduated-tier" +import ( + "fmt" -func GetSysdigSecureCostComponents(r *ResourceInstance) []*schema.CostComponent { - if r.Plan == TRIAL_PLAN_PROGRAMMATIC_NAME { + "github.com/infracost/infracost/internal/schema" + "github.com/shopspring/decimal" +) + +const SCCWP_GRADUATED_PLAN_PROGRAMMATIC_NAME string = "graduated-tier" +const SCCWP_TRIAL_PLAN_PROGRAMMATIC_NAME string = "free-trial" + +func GetSCCWPCostComponents(r *ResourceInstance) []*schema.CostComponent { + if r.Plan == SCCWP_TRIAL_PLAN_PROGRAMMATIC_NAME { + costComponent := schema.CostComponent{ + Name: "Free Trial", + UnitMultiplier: decimal.NewFromInt(1), + MonthlyQuantity: decimalPtr(decimal.NewFromInt(1)), + } + costComponent.SetCustomPrice(decimalPtr(decimal.NewFromInt(0))) return []*schema.CostComponent{ - // TODO + &costComponent, } - } else if r.Plan == GRADUATED_PLAN_PROGRAMMATIC_NAME { + } else if r.Plan == SCCWP_GRADUATED_PLAN_PROGRAMMATIC_NAME { return []*schema.CostComponent{ - // TODO + SCCWPMultiCloudCSPMComputeInstancesCostComponent(r), + SCCWPNodeHoursCostComponent(r), + SCCWPVMNodeHoursCostComponent(r), } } else { costComponent := schema.CostComponent{ @@ -25,4 +40,92 @@ func GetSysdigSecureCostComponents(r *ResourceInstance) []*schema.CostComponent } } -func SysdigSecure \ No newline at end of file +/* + * Graduated Tier Plan: 6 tiers + */ +func SCCWPMultiCloudCSPMComputeInstancesCostComponent(r *ResourceInstance) *schema.CostComponent { + + var quantity *decimal.Decimal + if r.SCCWP_MulticloudCSPMComputeInstances != nil { + quantity = decimalPtr(decimal.NewFromFloat(*r.SCCWP_MulticloudCSPMComputeInstances)) + } + + costComponent := schema.CostComponent{ + Name: "Multi-Cloud CSPM Compute Instance Hours", + Unit: "Instance-Hours", + UnitMultiplier: decimal.NewFromInt(1), + MonthlyQuantity: quantity, + 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("MULTI_CLOUD_CSPM_COMPUTE_INSTANCES"), + }, + } + return &costComponent +} + +/* + * Graduated Tier Plan: 6 tiers + */ +func SCCWPNodeHoursCostComponent(r *ResourceInstance) *schema.CostComponent { + + var quantity *decimal.Decimal + if r.SCCWP_NodeHours != nil { + quantity = decimalPtr(decimal.NewFromFloat(*r.SCCWP_NodeHours)) + } + + costComponent := schema.CostComponent{ + Name: "Node Hours", + Unit: "Instance-Hours", + UnitMultiplier: decimal.NewFromInt(1), + MonthlyQuantity: quantity, + 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("NODE_HOURS"), + }, + } + return &costComponent +} + +/* + * Graduated Tier Plan: 6 tiers + */ +func SCCWPVMNodeHoursCostComponent(r *ResourceInstance) *schema.CostComponent { + + var quantity *decimal.Decimal + if r.SCCWP_VMNodeHours != nil { + quantity = decimalPtr(decimal.NewFromFloat(*r.SCCWP_VMNodeHours)) + } + + costComponent := schema.CostComponent{ + Name: "VM Node Hours", + Unit: "Instance-Hours", + UnitMultiplier: decimal.NewFromInt(1), + MonthlyQuantity: quantity, + 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("VM_NODE_HOUR"), + }, + } + return &costComponent +} From 62a7cc3df04f575f1718611643222041216bccb6 Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Thu, 25 Apr 2024 16:58:29 -0400 Subject: [PATCH 5/8] Define SCC WP usage unit variables --- internal/resources/ibm/resource_instance.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/resources/ibm/resource_instance.go b/internal/resources/ibm/resource_instance.go index 20dec06d8f6..3085f387375 100644 --- a/internal/resources/ibm/resource_instance.go +++ b/internal/resources/ibm/resource_instance.go @@ -78,6 +78,10 @@ type ResourceInstance struct { SCC_Evaluations *float64 `infracost_usage:"scc_evaluations"` // Watson Studio WS_CUH *float64 `infracost_usage:"data-science-experience_CAPACITY_UNIT_HOURS"` + // SCC Workload Protection (Sysdig Secure) + SCCWP_MulticloudCSPMComputeInstances *float64 `infracost_usage:"sysdig-secure_MULTI_CLOUD_CSPM_COMPUTE_INSTANCES"` + SCCWP_NodeHours *float64 `infracost_usage:"sysdig-secure_NODE_HOURS"` + SCCWP_VMNodeHours *float64 `infracost_usage:"sysdig-secure_VM_NODE_HOUR"` } type ResourceCostComponentsFunc func(*ResourceInstance) []*schema.CostComponent @@ -122,6 +126,9 @@ var ResourceInstanceUsageSchema = []*schema.UsageItem{ {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}, + {Key: "sysdig-secure_MULTI_CLOUD_CSPM_COMPUTE_INSTANCES", DefaultValue: 0, ValueType: schema.Float64}, + {Key: "sysdig-secure_NODE_HOURS", DefaultValue: 0, ValueType: schema.Float64}, + {Key: "sysdig-secure_VM_NODE_HOUR", DefaultValue: 0, ValueType: schema.Float64}, } var ResourceInstanceCostMap map[string]ResourceCostComponentsFunc = map[string]ResourceCostComponentsFunc{ @@ -139,6 +146,7 @@ var ResourceInstanceCostMap map[string]ResourceCostComponentsFunc = map[string]R "discovery": GetWDCostComponents, "compliance": GetSCCCostComponents, "data-science-experience": GetWSCostComponents, + "sysdig-secure": GetSCCWPCostComponents, } func KMSKeyVersionsFreeCostComponent(r *ResourceInstance) *schema.CostComponent { From d743adb3bb1281b214e7d88baf215a9f0f3b7289 Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Thu, 25 Apr 2024 16:58:29 -0400 Subject: [PATCH 6/8] Define SCC WP usage unit variables From 0e5d1fa05ea4ebc9143e574538209195738dfdff Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Thu, 25 Apr 2024 16:59:06 -0400 Subject: [PATCH 7/8] Add SCC WP default usage units to usage file --- infracost-usage-example.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/infracost-usage-example.yml b/infracost-usage-example.yml index c1cac82930f..04321fd40e4 100644 --- a/infracost-usage-example.yml +++ b/infracost-usage-example.yml @@ -79,6 +79,9 @@ resource_type_default_usage: wd_collections: 301 scc_evaluations: 1 data-science-experience_CAPACITY_UNIT_HOURS: 1 + sysdig-secure_MULTI_CLOUD_CSPM_COMPUTE_INSTANCES: 0 + sysdig-secure_NODE_HOURS: 0 + sysdig-secure_VM_NODE_HOUR: 501 ibm_tg_gateway: connection: 3 data_transfer_global: 1000 @@ -1335,6 +1338,11 @@ resource_usage: ibm_resource_instance.watson_studio_professional: data-science-experience_CAPACITY_UNIT_HOURS: 1 # Amount of Capacity Unit-Hours used in a month + ibm_resource_instance.sccwp_graduated_tier: + sysdig-secure_MULTI_CLOUD_CSPM_COMPUTE_INSTANCES: 0 + sysdig-secure_NODE_HOURS: 0 + sysdig-secure_VM_NODE_HOUR: 501 + 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 From 82973a334cb14ad2fd8c6f8eef5b2aedd88f191e Mon Sep 17 00:00:00 2001 From: Luisa Rojas Date: Thu, 25 Apr 2024 16:59:45 -0400 Subject: [PATCH 8/8] Add TF tests for SCC WP --- .../resource_instance_test.golden | 26 ++++++++++++++++--- .../resource_instance_test.tf | 12 ++++++++- .../resource_instance_test.usage.yml | 5 ++++ 3 files changed, 39 insertions(+), 4 deletions(-) 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 53d90bc9a31..a8262436220 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 @@ -89,6 +89,26 @@ ibm_resource_instance.scc_trial └─ Trial 1 $0.00 + ibm_resource_instance.sccwp_graduated_tier + ├─ Multi-Cloud CSPM Compute Instance Hours (first 25 Instance-Hours) 25 Instance-Hours $206.00 + ├─ Multi-Cloud CSPM Compute Instance Hours (next 25 Instance-Hours) 25 Instance-Hours $175.10 + ├─ Multi-Cloud CSPM Compute Instance Hours (next 50 Instance-Hours) 50 Instance-Hours $309.00 + ├─ Multi-Cloud CSPM Compute Instance Hours (next 150 Instance-Hours) 150 Instance-Hours $865.20 + ├─ Multi-Cloud CSPM Compute Instance Hours (next 250 Instance-Hours) 250 Instance-Hours $1,236.00 + ├─ Multi-Cloud CSPM Compute Instance Hours (over 500 Instance-Hours) 1 Instance-Hours $4.53 + ├─ Node Hours (first 3 Instance-Hours) 3 Instance-Hours $0.19 + ├─ Node Hours (next 2 Instance-Hours) 2 Instance-Hours $0.11 + ├─ Node Hours (next 5 Instance-Hours) 5 Instance-Hours $0.24 + ├─ Node Hours (next 15 Instance-Hours) 15 Instance-Hours $0.68 + ├─ Node Hours (next 25 Instance-Hours) 25 Instance-Hours $0.97 + ├─ Node Hours (over 50 Instance-Hours) 1 Instance-Hours $0.04 + └─ VM Node Hours (first 25 Instance-Hours) 25 Instance-Hours $0.56 + └─ VM Node Hours (next 25 Instance-Hours) 25 Instance-Hours $0.47 + └─ VM Node Hours (next 50 Instance-Hours) 50 Instance-Hours $0.83 + └─ VM Node Hours (next 150 Instance-Hours) 150 Instance-Hours $2.33 + └─ VM Node Hours (next 250 Instance-Hours) 250 Instance-Hours $3.33 + └─ VM Node Hours (over 500 Instance-Hours) 1 Instance-Hours $0.01 + ibm_resource_instance.wa_instance_enterprise ├─ Instance (50000 MAU included) 1 Instance $6,000.00 ├─ Additional Monthly Active Users 1 1K MAU $120.00 @@ -139,7 +159,7 @@ ├─ Class 2 Resource Units 50 RU $0.09 └─ Class 3 Resource Units 50 RU $0.25 - OVERALL TOTAL $15,470.56 + OVERALL TOTAL $18,276.15 ────────────────────────────────── -32 cloud resources were detected: -∙ 32 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file \ No newline at end of file +33 cloud resources were detected: +∙ 33 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 9ad9387a000..e870d8f0c07 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 @@ -239,6 +239,7 @@ resource "ibm_resource_instance" "scc_trial" { resource_group_id = "default" } +# Watson Studio resource "ibm_resource_instance" "watson_studio_professional" { name = "ws_professional" service = "data-science-experience" @@ -248,9 +249,18 @@ resource "ibm_resource_instance" "watson_studio_professional" { } resource "ibm_resource_instance" "watson_studio_lite" { - name = "ws_lie" + name = "ws_lite" service = "data-science-experience" plan = "free-v1" location = "us-south" resource_group_id = "default" } + +# Security and Compliance Center (SCC) Workload Protection +resource "ibm_resource_instance" "sccwp_graduated_tier" { + name = "sccwp_graduated_tier" + service = "sysdig-secure" + plan = "graduated-tier" + 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 8164eca782b..b41c0056ea7 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 @@ -86,3 +86,8 @@ resource_usage: ibm_resource_instance.watson_studio_lite: data-science-experience_CAPACITY_UNIT_HOURS: 10 + + ibm_resource_instance.sccwp_graduated_tier: + sysdig-secure_MULTI_CLOUD_CSPM_COMPUTE_INSTANCES: 501 # Tier 6: 500-999999999 + sysdig-secure_NODE_HOURS: 51 # Tier 6: 50-999999999999999 + sysdig-secure_VM_NODE_HOUR: 501 # Tier 6: 500-999999999