Skip to content

Commit

Permalink
Add support for Event Streams resources (#183)
Browse files Browse the repository at this point in the history
* Add free Event Streams resources

* Add GC service ID for messagehub

* Add TF test resources for all messagehub plans

* Add usage units variables for messagehub

* Add unit variables to usage file

* Add skeleton for cost components

* Complete cost components for messagehub

* Add test usage

* Update golden file
  • Loading branch information
luisarojas authored Jul 29, 2024
1 parent 8c3ab76 commit 08fb3b2
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 5 deletions.
25 changes: 25 additions & 0 deletions infracost-usage-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ resource_type_default_usage:
dns-svcs_qty_custom_resolver_locations: 1 # Number of resolver locations
dns-svcs_qty_glb_instances: 1 # Number of GLBs
dns-svcs_qty_pools: 1 # Number of pools
messagehub_CAPACITY_UNIT_HOURS: 1
messagehub_qty_capacity_units: 1
messagehub_CAPACITY_UNIT_HOURS_ADDITIONAL: 1
messagehub_qty_capacity_units_additional: 1
messagehub_CAPACITY_UNIT_HOURS_MIRRORING: 1
messagehub_qty_capacity_units_mirroring: 1
messagehub_INSTANCE_HOURS: 1
messagehub_qty_instances: 1
messagehub_TERABYTE_HOURS: 1
messagehub_qty_terabytes: 1
messagehub_GIGABYTE_TRANSMITTED_OUTBOUNDS: 1

ibm_tg_gateway:
connection: 3
Expand Down Expand Up @@ -1372,6 +1383,20 @@ resource_usage:
dns-svcs_qty_custom_resolver_locations: 1 # Number of resolver locations
dns-svcs_qty_glb_instances: 1 # Number of GLBs
dns-svcs_qty_pools: 1 # Number of pools

ibm_resource_instance.event_streams:
messagehub_CAPACITY_UNIT_HOURS: 1
messagehub_qty_capacity_units: 1
messagehub_CAPACITY_UNIT_HOURS_ADDITIONAL: 1
messagehub_qty_capacity_units_additional: 1
messagehub_CAPACITY_UNIT_HOURS_MIRRORING: 1
messagehub_qty_capacity_units_mirroring: 1
messagehub_INSTANCE_HOURS: 1
messagehub_qty_instances: 1
messagehub_TERABYTE_HOURS: 1
messagehub_qty_terabytes: 1
messagehub_GIGABYTE_TRANSMITTED_OUTBOUNDS: 1


ibm_tg_gateway.tg_gateway:
connection: 25 # Monthly number of connections to the gateway
Expand Down
1 change: 1 addition & 0 deletions internal/providers/terraform/ibm/ibm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var globalCatalogServiceId = map[string]catalogMetadata{
"continuous-delivery": {"59b735ee-5938-4ebd-a6b2-541aef2d1f68", []string{}, nil, "https://cloud.ibm.com/catalog/services/continuous-delivery"},
"compliance": {"compliance", []string{}, nil, "https://cloud.ibm.com/catalog/services/security-and-compliance-center"},
"dns-svcs": {"b4ed8a30-936f-11e9-b289-1d079699cbe5", []string{}, nil, "https://cloud.ibm.com/catalog/services/dns-services"},
"messagehub": {"6a7f4e38-f218-48ef-9dd2-df408747568e", []string{}, nil, "https://cloud.ibm.com/eventstreams-provisioning/6a7f4e38-f218-48ef-9dd2-df408747568e/create"},
}

func SetCatalogMetadata(d *schema.ResourceData, resourceType string, config map[string]any) {
Expand Down
2 changes: 2 additions & 0 deletions internal/providers/terraform/ibm/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var FreeResources = []string{
"ibm_container_addons",
"ibm_cos_bucket_object_lock_configuration",
"ibm_dns_custom_resolver",
"ibm_event_streams_schema",
"ibm_event_streams_topic",
"ibm_iam_access_group",
"ibm_iam_access_group_account_settings",
"ibm_iam_access_group_dynamic_rule",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
└─ Additional Million DNS Queries (first 999 Million Queries) 999 Million Queries $645.16
└─ Additional Million DNS Queries (over 999 Million Queries) 1 Million Queries $0.32

ibm_resource_instance.messagehub_enterprise
├─ Base Capacity Unit-Hour 1 Hours $7.37
├─ Additional Capacity Unit-Hour 1 Hours $7.37
├─ Additional Storage Terabyte per Hour 10 Hours $6.46
├─ Gigabyte Transmitted Outbound 100 GB $8.61
└─ Mirroring Capacity Unit-Hour 1 Hours $1.47

ibm_resource_instance.messagehub_lite
└─ Lite plan 1 $0.00

ibm_resource_instance.messagehub_satellite
├─ Base Capacity Unit-Hour 1 Hours $7.37
└─ Additional Capacity Unit-Hour 1 Hours $7.37

ibm_resource_instance.messagehub_standard
├─ Partition Hours 100 Hours $1.50
└─ Gigabyte Transmitted Outbound 100 GB $8.61

ibm_resource_instance.resource_instance_activity_tracker_7day
└─ Gigabyte Months 10 Gigabyte Months $16.15

Expand Down Expand Up @@ -179,7 +197,7 @@
├─ Class 2 Resource Units 50 RU $0.09
└─ Class 3 Resource Units 50 RU $0.25

OVERALL TOTAL $19,248.98
OVERALL TOTAL $19,305.11
──────────────────────────────────
37 cloud resources were detected:
37 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
41 cloud resources were detected:
41 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 @@ -2,7 +2,7 @@ terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.63.0"
version = "1.64.0"
}
}
}
Expand Down Expand Up @@ -296,4 +296,36 @@ resource "ibm_resource_instance" "dns_svcs_standard" {
plan = "standard-dns"
location = "global"
resource_group_id = "default"
}
}

resource "ibm_resource_instance" "messagehub_lite" {
name = "messagehub_lite"
service = "messagehub"
plan = "lite"
location = "us-south"
resource_group_id = "default"
}

resource "ibm_resource_instance" "messagehub_standard" {
name = "messagehub_standard"
service = "messagehub"
plan = "standard"
location = "us-south"
resource_group_id = "default"
}

resource "ibm_resource_instance" "messagehub_enterprise" {
name = "messagehub_enterprise"
service = "messagehub"
plan = "enterprise-3nodes-2tb"
location = "us-south"
resource_group_id = "default"
}

resource "ibm_resource_instance" "messagehub_satellite" {
name = "messagehub_satellite"
service = "messagehub"
plan = "satellite"
location = "satcon_dal"
resource_group_id = "default"
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,38 @@ resource_usage:
dns-svcs_qty_custom_resolver_locations: 1 # Number of resolver locations
dns-svcs_qty_glb_instances: 1 # Number of GLBs
dns-svcs_qty_pools: 1 # Number of pools

ibm_resource_instance.messagehub_lite:
messagehub_CAPACITY_UNIT_HOURS: 1
messagehub_qty_capacity_units: 1
messagehub_CAPACITY_UNIT_HOURS_ADDITIONAL: 1
messagehub_qty_capacity_units_additional: 1
messagehub_CAPACITY_UNIT_HOURS_MIRRORING: 1
messagehub_qty_capacity_units_mirroring: 1
messagehub_INSTANCE_HOURS: 1
messagehub_qty_instances: 1
messagehub_TERABYTE_HOURS: 1
messagehub_qty_terabytes: 1
messagehub_GIGABYTE_TRANSMITTED_OUTBOUNDS: 1

ibm_resource_instance.messagehub_standard:
messagehub_INSTANCE_HOURS: 100
messagehub_qty_instances: 1
messagehub_GIGABYTE_TRANSMITTED_OUTBOUNDS: 100

ibm_resource_instance.messagehub_enterprise:
messagehub_CAPACITY_UNIT_HOURS: 1
messagehub_qty_capacity_units: 1
messagehub_CAPACITY_UNIT_HOURS_ADDITIONAL: 1
messagehub_qty_capacity_units_additional: 1
messagehub_CAPACITY_UNIT_HOURS_MIRRORING: 1
messagehub_qty_capacity_units_mirroring: 1
messagehub_TERABYTE_HOURS: 10
messagehub_qty_terabytes: 1
messagehub_GIGABYTE_TRANSMITTED_OUTBOUNDS: 100

ibm_resource_instance.messagehub_satellite:
messagehub_CAPACITY_UNIT_HOURS: 1
messagehub_qty_capacity_units: 1
messagehub_CAPACITY_UNIT_HOURS_ADDITIONAL: 1
messagehub_qty_capacity_units_additional: 1
24 changes: 24 additions & 0 deletions internal/resources/ibm/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ type ResourceInstance struct {
DNSServices_PoolHours *float64 `infracost_usage:"dns-svcs_NUMBERPOOLS"`
DNSServices_Pools *int64 `infracost_usage:"dns-svcs_qty_pools"`
DNSServices_Zones *int64 `infracost_usage:"dns-svcs_ITEMS"`
// Event Streams
EventStreams_CapacityUnitHours *float64 `infracost_usage:"messagehub_CAPACITY_UNIT_HOURS"`
EventStreams_CapacityUnitHoursAdditional *float64 `infracost_usage:"messagehub_CAPACITY_UNIT_HOURS_ADDITIONAL"`
EventStreams_CapacityUnitHoursMirroring *float64 `infracost_usage:"messagehub_CAPACITY_UNIT_HOURS_MIRRORING"`
EventStreams_CapacityUnits *float64 `infracost_usage:"messagehub_qty_capacity_units"`
EventStreams_CapacityUnitsAdditional *float64 `infracost_usage:"messagehub_qty_capacity_units_additional"`
EventStreams_CapacityUnitsMirroring *float64 `infracost_usage:"messagehub_qty_capacity_units_mirroring"`
EventStreams_GigabyteTransmittedOutbounds *float64 `infracost_usage:"messagehub_GIGABYTE_TRANSMITTED_OUTBOUNDS"`
EventStreams_InstanceHours *float64 `infracost_usage:"messagehub_INSTANCE_HOURS"`
EventStreams_Instances *float64 `infracost_usage:"messagehub_qty_instances"`
EventStreams_TerabyteHours *float64 `infracost_usage:"messagehub_TERABYTE_HOURS"`
EventStreams_Terabytes *float64 `infracost_usage:"messagehub_qty_terabytes"`
}

type ResourceCostComponentsFunc func(*ResourceInstance) []*schema.CostComponent
Expand Down Expand Up @@ -154,6 +166,17 @@ var ResourceInstanceUsageSchema = []*schema.UsageItem{
{Key: "dns-svcs_qty_custom_resolver_locations", DefaultValue: 1, ValueType: schema.Int64},
{Key: "dns-svcs_qty_glb_instances", DefaultValue: 1, ValueType: schema.Int64},
{Key: "dns-svcs_qty_pools", DefaultValue: 1, ValueType: schema.Int64},
{Key: "messagehub_CAPACITY_UNIT_HOURS", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_CAPACITY_UNIT_HOURS_ADDITIONAL", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_CAPACITY_UNIT_HOURS_MIRRORING", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_qty_capacity_units", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_qty_capacity_units_additional", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_qty_capacity_units_mirroring", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_GIGABYTE_TRANSMITTED_OUTBOUNDS", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_INSTANCE_HOURS", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_qty_instances", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_TERABYTE_HOURS", DefaultValue: 1, ValueType: schema.Float64},
{Key: "messagehub_qty_terabytes", DefaultValue: 1, ValueType: schema.Float64},
}

var ResourceInstanceCostMap map[string]ResourceCostComponentsFunc = map[string]ResourceCostComponentsFunc{
Expand All @@ -174,6 +197,7 @@ var ResourceInstanceCostMap map[string]ResourceCostComponentsFunc = map[string]R
"sysdig-secure": GetSCCWPCostComponents,
"aiopenscale": GetWGOVCostComponents,
"dns-svcs": GetDNSServicesCostComponents,
"messagehub": GetEventStreamsCostComponents,
}

func KMSKeyVersionsFreeCostComponent(r *ResourceInstance) *schema.CostComponent {
Expand Down
Loading

0 comments on commit 08fb3b2

Please sign in to comment.