Skip to content

Commit

Permalink
feat: add pricing urls to metadata (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltol authored May 2, 2024
1 parent f72fb4b commit b4c65a5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 58 deletions.
16 changes: 8 additions & 8 deletions infracost-usage-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ resource_type_default_usage:
secretsmanager_instance: 1
logdna_gigabyte_months: 1
activitytracker_gigabyte_months: 1
monitoring_node_hour: 700
monitoring_container_hour: 700
monitoring_api_call: 1000
monitoring_timeseries_hour: 1000
sysdig-monitor_NODE_HOURS: 700
sysdig-monitor_CONTAINER_HOURS: 700
sysdig-monitor_API_CALL_HOURS: 1000
sysdig-monitor_TIME_SERIES_HOURS: 1000
continuousdelivery_authorized_users: 1
wml_capacity_unit_hour: 20
wml_instance: 1
Expand Down Expand Up @@ -1301,10 +1301,10 @@ resource_usage:
appconnect_vcpu_hours: 10 # The number of VCPU hours used in a month
logdna_gigabyte_months: 10 # The amount of logs in a month in GB
activitytracker_gigabyte_months: 10 # The amount of logs in a month in GB
monitoring_node_hour: 700 # The amount of hours monitoring runs on a host in a month
monitoring_container_hour: 700 # Additional containers on a host above the base 50
monitoring_api_call: 1000 # Additional API calls above the base 1M/instance
monitoring_timeseries_hour: 1000 # Additional time-series cost above the base 1000/host
sysdig-monitor_NODE_HOURS: 700 # The amount of hours monitoring runs on a host in a month
sysdig-monitor_CONTAINER_HOURS: 700 # Additional containers on a host above the base 50
sysdig-monitor_API_CALL_HOURS: 1000 # Additional API calls above the base 1M/instance
sysdig-monitor_TIME_SERIES_HOURS: 1000 # Additional time-series cost above the base 1000/host
continuousdelivery_authorized_users: 10 # Number of authorized users to the CD instance and its managed toolchains

ibm_resource_instance.watson_machine_learning_standard:
Expand Down
62 changes: 33 additions & 29 deletions internal/providers/terraform/ibm/ibm.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,53 @@ type catalogMetadata struct {
serviceId string
childResources []string
configuration map[string]any
pricingUrl string
}

// Map between terraform type and global catalog id. For ibm_resource_instance, the service
// field already matches the global catalog id, so they do not need to be mapped. eg: "kms"
var globalCatalogServiceId = map[string]catalogMetadata{
"ibm_is_vpc": {"is.vpc", []string{"ibm_is_flow_log"}, nil},
"ibm_container_vpc_cluster": {"containers-kubernetes", []string{}, nil},
"ibm_container_vpc_worker_pool": {"containers-kubernetes", []string{}, nil},
"ibm_is_instance": {"is.instance", []string{"ibm_is_ssh_key", "ibm_is_floating_ip"}, nil},
"ibm_is_volume": {"is.volume", []string{}, nil},
"ibm_is_vpn_gateway": {"is.vpn", []string{}, nil},
"ibm_tg_gateway": {"f38a4da0-c353-11e9-83b6-a36a57a97a06", []string{}, nil},
"ibm_is_floating_ip": {"is.floating-ip", []string{}, nil},
"ibm_is_flow_log": {"is.flow-log-collector", []string{}, nil},
"ibm_cloudant": {"Cloudant", []string{}, nil},
"ibm_pi_instance": {"Power Systems Virtual Server", []string{}, nil},
"ibm_pi_volume": {"Power Systems Storage Volume", []string{}, nil},
"ibm_cos_bucket": {"Object Storage Bucket", []string{}, nil},
"ibm_is_lb": {"is.load-balancer", []string{}, nil},
"ibm_is_public_gateway": {"is.public-gateway", []string{"ibm_is_floating_ip"}, nil},
"kms": {"ee41347f-b18e-4ca6-bf80-b5467c63f9a6", []string{}, nil},
"cloud-object-storage": {"dff97f5c-bc5e-4455-b470-411c3edbe49c", []string{}, nil},
"roks": {"containers.kubernetes.cluster.roks", []string{}, nil},
"pm-20": {"51c53b72-918f-4869-b834-2d99eb28422a", []string{}, nil},
"data-science-experience": {"39ba9d4c-b1c5-4cc3-a163-38b580121e01", []string{}, nil},
"discovery": {"76b7bf22-b443-47db-b3db-066ba2988f47", []string{}, nil},
"wx": {"51c53b72-918f-4869-b834-2d99eb28422a", []string{}, nil},
"conversation": {"7045626d-55e3-4418-be11-683a26dbc1e5", []string{}, nil},
"aiopenscale": {"2ad019f3-0fd6-4c25-966d-f3952481a870", []string{}, nil},
"sysdig-monitor": {"090c2c10-8c38-11e8-bec2-493df9c49eb8", []string{}, nil},
"sysdig-secure": {"e831e900-82d6-11ec-95c5-c12c5a5d9687", []string{}, nil},
"logdna": {"e13e1860-959c-11e8-871e-ad157af61ad7", []string{}, nil},
"ibm_is_vpc": {"is.vpc", []string{"ibm_is_flow_log"}, nil, "https://cloud.ibm.com/vpc-ext/provision/vpc"},
"ibm_container_vpc_cluster": {"containers-kubernetes", []string{}, nil, "https://cloud.ibm.com/kubernetes/catalog/about#pricing"},
"ibm_container_vpc_worker_pool": {"containers-kubernetes", []string{}, nil, "https://cloud.ibm.com/kubernetes/catalog/about#pricing"},
"ibm_is_instance": {"is.instance", []string{"ibm_is_ssh_key", "ibm_is_floating_ip"}, nil, "https://cloud.ibm.com/vpc-ext/provision/vs"},
"ibm_is_volume": {"is.volume", []string{}, nil, "https://cloud.ibm.com/vpc-ext/provision/storage"},
"ibm_is_vpn_gateway": {"is.vpn", []string{}, nil, "https://cloud.ibm.com/vpc-ext/provision/vpngateway"},
"ibm_tg_gateway": {"f38a4da0-c353-11e9-83b6-a36a57a97a06", []string{}, nil, "https://cloud.ibm.com/interconnectivity/transit/provision"},
"ibm_is_floating_ip": {"is.floating-ip", []string{}, nil, "https://cloud.ibm.com/vpc-ext/provision/vs"},
"ibm_is_flow_log": {"is.flow-log-collector", []string{}, nil, "https://cloud.ibm.com/vpc-ext/provision/flowLog"},
"ibm_cloudant": {"Cloudant", []string{}, nil, "https://cloud.ibm.com/catalog/services/cloudant"},
"ibm_pi_instance": {"Power Systems Virtual Server", []string{}, nil, "https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-pricing-virtual-server"},
"ibm_pi_volume": {"Power Systems Storage Volume", []string{}, nil, "https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-pricing-virtual-server#storage-type"},
"ibm_cos_bucket": {"Object Storage Bucket", []string{}, nil, "https://cloud.ibm.com/objectstorage/create#pricing"},
"ibm_is_lb": {"is.load-balancer", []string{}, nil, "https://cloud.ibm.com/vpc-ext/provision/loadBalancer"},
"ibm_is_public_gateway": {"is.public-gateway", []string{"ibm_is_floating_ip"}, nil, "https://cloud.ibm.com/vpc-ext/provision/vpc"},
"kms": {"ee41347f-b18e-4ca6-bf80-b5467c63f9a6", []string{}, nil, "https://cloud.ibm.com/catalog/services/key-protect"},
"cloud-object-storage": {"dff97f5c-bc5e-4455-b470-411c3edbe49c", []string{}, nil, "https://cloud.ibm.com/objectstorage/create#pricing"},
"roks": {"containers.kubernetes.cluster.roks", []string{}, nil, "https://cloud.ibm.com/kubernetes/catalog/about?platformType=openshift"},
"pm-20": {"51c53b72-918f-4869-b834-2d99eb28422a", []string{}, nil, "https://cloud.ibm.com/catalog/services/watson-machine-learning"},
"data-science-experience": {"39ba9d4c-b1c5-4cc3-a163-38b580121e01", []string{}, nil, "https://cloud.ibm.com/catalog/services/watson-studio"},
"discovery": {"76b7bf22-b443-47db-b3db-066ba2988f47", []string{}, nil, "https://cloud.ibm.com/catalog/services/watson-discovery"},
"wx": {"51c53b72-918f-4869-b834-2d99eb28422a", []string{}, nil, "https://cloud.ibm.com/watsonx/overview"},
"conversation": {"7045626d-55e3-4418-be11-683a26dbc1e5", []string{}, nil, "https://cloud.ibm.com/catalog/services/watsonx-assistant"},
"aiopenscale": {"2ad019f3-0fd6-4c25-966d-f3952481a870", []string{}, nil, "https://cloud.ibm.com/catalog/services/watsonxgovernance"},
"sysdig-monitor": {"090c2c10-8c38-11e8-bec2-493df9c49eb8", []string{}, nil, "https://cloud.ibm.com/observe/catalog/ibm-cloud-monitoring"},
"sysdig-secure": {"e831e900-82d6-11ec-95c5-c12c5a5d9687", []string{}, nil, "https://cloud.ibm.com/workload-protection/catalog/security-and-compliance-center-workload-protection"},
"logdna": {"e13e1860-959c-11e8-871e-ad157af61ad7", []string{}, nil, "https://cloud.ibm.com/catalog/services/logdna"},
"databases-for-postgresql": {"databases-for-postgresql", []string{}, nil, "https://cloud.ibm.com/databases/databases-for-postgresql/create"},
}

func SetCatalogMetadata(d *schema.ResourceData, resourceType string, config map[string]any) {
metadata := make(map[string]gjson.Result)
var properties gjson.Result
var serviceId string = resourceType
var childResources []string
var pricingUrl string

catalogEntry, isPresent := globalCatalogServiceId[resourceType]
if isPresent {
serviceId = catalogEntry.serviceId
pricingUrl = catalogEntry.pricingUrl
childResources = catalogEntry.childResources
}

Expand All @@ -104,12 +108,12 @@ func SetCatalogMetadata(d *schema.ResourceData, resourceType string, config map[

properties = gjson.Result{
Type: gjson.JSON,
Raw: fmt.Sprintf(`{"serviceId": "%s" , "childResources": %s, "configuration": %s}`, serviceId, childResourcesString, configString),
Raw: fmt.Sprintf(`{"serviceId": "%s" , "pricingUrl": "%s", "childResources": %s, "configuration": %s}`, serviceId, pricingUrl, childResourcesString, configString),
}
} else {
properties = gjson.Result{
Type: gjson.JSON,
Raw: fmt.Sprintf(`{"serviceId": "%s", "configuration": %s}`, serviceId, configString),
Raw: fmt.Sprintf(`{"serviceId": "%s", "pricingUrl": "%s", "configuration": %s}`, serviceId, pricingUrl, configString),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ resource_usage:
ibm_resource_instance.resource_instance_activity_tracker_lite:
activitytracker_gigabyte_months: 10
ibm_resource_instance.resource_instance_monitoring_lite:
monitoring_node_hour: 730
monitoring_container_hour: 10
monitoring_api_call: 100000
monitoring_timeseries_hour: 100
sysdig-monitor_NODE_HOURS: 730
sysdig-monitor_CONTAINER_HOURS: 10
sysdig-monitor_API_CALL_HOURS: 100000
sysdig-monitor_TIME_SERIES_HOURS: 100
ibm_resource_instance.resource_instance_monitoring_graduated:
monitoring_node_hour: 730
monitoring_container_hour: 1460
monitoring_api_call: 100000
monitoring_timeseries_hour: 100
sysdig-monitor_NODE_HOURS: 730
sysdig-monitor_CONTAINER_HOURS: 1460
sysdig-monitor_API_CALL_HOURS: 100000
sysdig-monitor_TIME_SERIES_HOURS: 100
ibm_resource_instance.resource_instance_monitoring_graduated_secure:
monitoring_node_hour: 730
monitoring_container_hour: 1460
monitoring_api_call: 100000
monitoring_timeseries_hour: 100
sysdig-monitor_NODE_HOURS: 730
sysdig-monitor_CONTAINER_HOURS: 1460
sysdig-monitor_API_CALL_HOURS: 100000
sysdig-monitor_TIME_SERIES_HOURS: 100
ibm_resource_instance.cd_instance_professional:
continuousdelivery_authorized_users: 2
ibm_resource_instance.wml_instance_lite:
Expand Down
17 changes: 8 additions & 9 deletions internal/resources/ibm/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ type ResourceInstance struct {
// Monitoring (Sysdig)
// Catalog https://cloud.ibm.com/catalog/services/ibm-cloud-monitoring
// Pricing https://cloud.ibm.com/docs/monitoring?topic=monitoring-pricing_plans
Monitoring_NodeHour *float64 `infracost_usage:"monitoring_node_hour"`
Monitoring_ContainerHour *float64 `infracost_usage:"monitoring_container_hour"`
Monitoring_APICall *float64 `infracost_usage:"monitoring_api_call"`
Monitoring_TimeSeriesHour *float64 `infracost_usage:"monitoring_timeseries_hour"`
Monitoring_NodeHour *float64 `infracost_usage:"sysdig-monitor_NODE_HOURS"`
Monitoring_ContainerHour *float64 `infracost_usage:"sysdig-monitor_CONTAINER_HOURS"`
Monitoring_APICall *float64 `infracost_usage:"sysdig-monitor_API_CALL_HOURS"`
Monitoring_TimeSeriesHour *float64 `infracost_usage:"sysdig-monitor_TIME_SERIES_HOURS"`
// Continuous Delivery
// Catalog https://cloud.ibm.com/catalog/services/continuous-delivery
// Pricing https://cloud.ibm.com/docs/ContinuousDelivery?topic=ContinuousDelivery-limitations_usage&interface=ui
Expand Down Expand Up @@ -108,11 +108,10 @@ var ResourceInstanceUsageSchema = []*schema.UsageItem{
{Key: "appconnect_vcpu_hours", DefaultValue: 0, ValueType: schema.Float64},
{Key: "logdna_gigabyte_months", DefaultValue: 0, ValueType: schema.Float64},
{Key: "activitytracker_gigabyte_months", DefaultValue: 0, ValueType: schema.Float64},
{Key: "monitoring_node_hour", DefaultValue: 0, ValueType: schema.Float64},
{Key: "monitoring_node_hour_lite", DefaultValue: 0, ValueType: schema.Float64},
{Key: "monitoring_container_hour", DefaultValue: 0, ValueType: schema.Float64},
{Key: "monitoring_api_call", DefaultValue: 0, ValueType: schema.Float64},
{Key: "monitoring_timeseries_hour", DefaultValue: 0, ValueType: schema.Float64},
{Key: "sysdig-monitor_NODE_HOURS", DefaultValue: 0, ValueType: schema.Float64},
{Key: "sysdig-monitor_CONTAINER_HOURS", DefaultValue: 0, ValueType: schema.Float64},
{Key: "sysdig-monitor_API_CALL_HOURS", DefaultValue: 0, ValueType: schema.Float64},
{Key: "sysdig-monitor_TIME_SERIES_HOURS", DefaultValue: 0, ValueType: schema.Float64},
{Key: "continuousdelivery_authorized_users", DefaultValue: 0, ValueType: schema.Int64},
{Key: "wml_capacity_unit_hour", DefaultValue: 0, ValueType: schema.Float64},
{Key: "wml_instance", DefaultValue: 0, ValueType: schema.Float64},
Expand Down

0 comments on commit b4c65a5

Please sign in to comment.