forked from infracost/infracost
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for SCC Workload Protection (#169)
* Create inital WP file & parent cost component * Fix function definition syntax * Change global var names to avoid clashing * Add cost components for SSC WP * Define SCC WP usage unit variables * Define SCC WP usage unit variables * Add SCC WP default usage units to usage file * Add TF tests for SCC WP
- Loading branch information
1 parent
435a6a0
commit 2d0c717
Showing
7 changed files
with
191 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
internal/resources/ibm/resource_instance_sysdig-secure.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package ibm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"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{ | ||
&costComponent, | ||
} | ||
} else if r.Plan == SCCWP_GRADUATED_PLAN_PROGRAMMATIC_NAME { | ||
return []*schema.CostComponent{ | ||
SCCWPMultiCloudCSPMComputeInstancesCostComponent(r), | ||
SCCWPNodeHoursCostComponent(r), | ||
SCCWPVMNodeHoursCostComponent(r), | ||
} | ||
} 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, | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* 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 | ||
} |